Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/joeqian10/neo3-gogogo
Browse files Browse the repository at this point in the history
  • Loading branch information
joeqian10 committed Dec 6, 2021
2 parents 8d3fe37 + 6a4d4f4 commit 8f4c705
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,28 @@ func main() {
}
```

#### 2.2.3 Convert base64 encoded script hash to standard address

```golang
package demo

import (
"github.com/joeqian10/neo3-gogogo/crypto"
"github.com/joeqian10/neo3-gogogo/helper"
)

func main() {
bs, err := crypto.Base64Decode("4rZTInKT6ZxPKQbVNVOrtKZy34Y=")
if err != nil {
// do something...
}
u := helper.UInt160FromBytes(bs)
a := crypto.ScriptHashToAddress(u, helper.DefaultAddressVersion)
// "a" is NgaiKFjurmNmiRzDRQGs44yzByXuSkdGPF
}

```

## 3. Modules Introduction

### 3.1 "block" module
Expand Down
8 changes: 8 additions & 0 deletions crypto/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ func TestScriptHashToAddress(t *testing.T) {
a := ScriptHashToAddress(u, helper.DefaultAddressVersion)
assert.Equal(t, "NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf", a)
}

func TestConvert(t *testing.T) {
bs, err := Base64Decode("4rZTInKT6ZxPKQbVNVOrtKZy34Y=")
assert.Nil(t, err)
u := helper.UInt160FromBytes(bs)
a := ScriptHashToAddress(u, helper.DefaultAddressVersion)
assert.Equal(t, "NgaiKFjurmNmiRzDRQGs44yzByXuSkdGPF", a)
}
2 changes: 1 addition & 1 deletion wallet/walletHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (w *WalletHelper) Transfer(assetHash *helper.UInt160, toAddress string, amo
}
balancesGas := make([]AccountAndBalance, 0)
if assetHash.Equals(tx.GasToken) {
balancesGas = FindRemainingAccountAndBalance(balancesUsed, balances)
balancesGas = balances
} else {
balancesGas, err = w.GetAccountAndBalance(tx.GasToken)
if err != nil {
Expand Down

0 comments on commit 8f4c705

Please sign in to comment.