Skip to content

Commit

Permalink
multiple op_returns, support raw bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Oct 2, 2020
1 parent 833c327 commit 43c2508
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 3 additions & 5 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ type PayToAddress struct {
}

// OpReturnData is the op return data to include in the tx
type OpReturnData struct {
Data string `json:"data"`
}
type OpReturnData [][]byte

// CreateTx will create a basic transaction
func CreateTx(utxos []*Utxo, addresses []*PayToAddress, opReturns []*OpReturnData, wif string) (string, error) {
func CreateTx(utxos []*Utxo, addresses []*PayToAddress, opReturns []OpReturnData, wif string) (string, error) {

// Missing utxos
if len(utxos) == 0 {
Expand Down Expand Up @@ -57,7 +55,7 @@ func CreateTx(utxos []*Utxo, addresses []*PayToAddress, opReturns []*OpReturnDat
// Loop any op returns
var outPut *output.Output
for _, op := range opReturns {
if outPut, err = output.NewOpReturn([]byte(op.Data)); err != nil {
if outPut, err = output.NewOpReturnParts(op); err != nil {
return "", err
}
tx.AddOutput(outPut)
Expand Down
5 changes: 3 additions & 2 deletions transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func TestCreateTx(t *testing.T) {
}

// Add some op return data
opReturn := &OpReturnData{Data: "This is the example data!"}
opReturn1 := OpReturnData{[]byte("prefix1"), []byte("example data"), []byte{0x13, 0x37}}
opReturn2 := OpReturnData{[]byte("prefix2"), []byte("more example data")}

// Generate the TX
rawTx, err := CreateTx([]*Utxo{utxo}, []*PayToAddress{payTo}, []*OpReturnData{opReturn}, "L3VJH2hcRGYYG6YrbWGmsxQC1zyYixA82YjgEyrEUWDs4ALgk8Vu")
rawTx, err := CreateTx([]*Utxo{utxo}, []*PayToAddress{payTo}, []OpReturnData{opReturn1, opReturn2}, "L3VJH2hcRGYYG6YrbWGmsxQC1zyYixA82YjgEyrEUWDs4ALgk8Vu")
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
Expand Down

0 comments on commit 43c2508

Please sign in to comment.