Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A nightmare to get the examples running. Release tag matrix from hell [BUG] #102

Open
golangdaddy opened this issue Dec 21, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@golangdaddy
Copy link

There are 3 conflicting examples in this repo for the same transaction.

Package module names don't match the filestructure... unintuitive and messy.

Generally needs harmonising with the readme so its enjoyable to use.

@golangdaddy golangdaddy added the bug Something isn't working label Dec 21, 2021
@jadwahab
Copy link
Member

Hi @golangdaddy, thanks for the general feedback. Can you please provide more details regarding which package module names do not match the file structure, the examples you're having issues with, and the "release tag matrix from hell"?

@golangdaddy
Copy link
Author

golangdaddy commented Dec 27, 2021

As a user I want to look at the repo and see the latest API/examples, and the whole thing be self-referential and intuitive, not having to follow examples that don't just work without some go mod wizardry with various releases.

Even following the examples and fixing the deps, I don't have a working example, so its not a very convenient package.

I'm trying to build an SDK over this, so have loads of questions, but as not-a-complete-noob I still have found this one of the most frustrating packages I have come across, happy to lend a hand.

@golangdaddy
Copy link
Author

I would be grateful to know if there is an interface between bip32.ExtendedKey and bec.PrivateKey, I'm building a wallet implementation to learn, which can hopefully have both working in the same manner.

@golangdaddy
Copy link
Author

golangdaddy commented Dec 27, 2021

import (
	"context"
	"fmt"

	"github.com/kr/pretty"
	"github.com/libsv/go-bk/bec"
	"github.com/libsv/go-bk/wif"
	"github.com/libsv/go-bt/v2"
	"github.com/libsv/go-bt/v2/bscript"
	"github.com/XXXXXXXX/bsv"
)

func (self *KeyInfo) SendSatoshisToAddress(satoshis uint64, scriptHash, address, changeAddress string) (string, error) {

	tx := bt.NewTx()
	var availableSatoshis uint64

	for _, in := range self.UsableInputs {
		availableSatoshis += uint64(in.Available * 100000000)
		if err := tx.From(
			in.Txid,
			uint32(in.Vout),
			scriptHash,
			uint64(satoshis),
		); err != nil {
			return "", err
		}
	}

	println("available satoshis", availableSatoshis)

	if availableSatoshis < satoshis+satoshis {
		return "", fmt.Errorf("not enough funds")
	}

	if err := tx.PayToAddress(address, uint64(satoshis)); err != nil {
		return "", err
	}

	fees := bt.NewFeeQuote()
	if err := tx.ChangeToAddress(address, fees); err != nil {
		return "", err
	}

	//_ = tx.AddOpReturnOutput([]byte("You are using go-bt!"))

	if err := tx.UnlockAll(
		context.Background(),
		&bt.LocalUnlockerGetter{
			PrivateKey: self.key,
		},
	); err != nil {
		return "", err
	}

	txHex := tx.String()
	println("HEX", txHex)

	if debugtx, err := whatsonchain.DecodeTransaction(txHex); err != nil {
		return "", err
	} else {
		pretty.Println("PENDING:")
		pretty.Println(debugtx)
	}

	return whatsonchain.PostTransaction(txHex)
}

The above code is what I have managed to glean from the various releases, I'm not confident that I have all the steps covered, as the examples are limited. Any help appreciated, then I can move on and make contributions

"unexpected response code 500: 16: mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation)"

@golangdaddy
Copy link
Author

golangdaddy commented Dec 27, 2021

Also the bec.PrivateKey when made into a bitcoin address with the go-bt repo generates a different address than the official instructions on the bitcoin sv website which I translated to this code:

func ClassicAddress(pubKeyBytes []byte) (string, error) {

	x := byte(0x00)
	xx := []byte{x}

	b := Ripemd(Sha256(pubKeyBytes))
	b = bytes.Join([][]byte{xx, b}, nil)
	c := b
	b = Sha256(b)
	b = Sha256(b)
	prefix := b[:4]
	d := bytes.Join([][]byte{c, prefix}, nil)
	return string(base58.FastBase58Encoding(d)), nil
}

WIF to address:
this repo: 1CpCPAibantXsg2Nuv2NKYPqx4ifaCmnE7
me following bitcoinsv.org instructions: 1AdZTNmwE2F5pduveoxNqYhizitnCV5GMP

This address has funds on it: 1AdZTNmwE2F5pduveoxNqYhizitnCV5GMP, was hoping this repo would generate the same address from the same WIF.

An explanation for this would be useful to include in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants