Skip to content

Commit

Permalink
fix: decode contract type, added decode demo (#8)
Browse files Browse the repository at this point in the history
* fix: decode contract type, added decode demo

* roll back default

* change demo decode tx to transfer

* added error treatment
  • Loading branch information
samufacanha2 authored Nov 4, 2022
1 parent aed35ee commit 5c859a1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions cmd/demo/decode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"

"github.com/klever-io/klever-go-sdk/cmd/demo"
"github.com/klever-io/klever-go-sdk/models"
)

func main() {

accounts, wallets, kc, err := demo.InitWallets()
if err != nil {
panic(err)
}

base := accounts[0].NewBaseTX()
tx, err := kc.MultiTransfer(
base,
"KLV",
[]models.ToAmount{{
ToAddress: accounts[1].Address().Bech32(),
Amount: 1000,
}})
if err != nil {
panic(err)
}

err = tx.Sign(wallets[0])
if err != nil {
panic(err)
}

decodedTx, err := kc.Decode(tx)
if err != nil {
panic(err)
}

fmt.Println("\n\n\nEncodedTX: ", tx)
fmt.Println("\n\n\nDecodedTX: ", decodedTx)
}
2 changes: 1 addition & 1 deletion models/transactionAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type TransactionAPI struct {
Signature []string `json:"signature,omitempty"`
SearchOrder uint32 `json:"searchOrder"`
Receipts []map[string]interface{} `json:"receipts"`
Contracts []*proto.TXContract `json:"contract"`
Contracts []*TXContractAPI `json:"contract"`
}

func (t *TransactionAPI) String() string {
Expand Down

0 comments on commit 5c859a1

Please sign in to comment.