wallet: add ScriptHash() method to Contract
This commit is contained in:
parent
a871f75063
commit
a798e4e0fa
2 changed files with 15 additions and 0 deletions
|
@ -5,7 +5,9 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
||||
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// Account represents a NEO account. It holds the private and public key
|
||||
|
@ -66,6 +68,11 @@ type contract struct {
|
|||
Deployed bool `json:"deployed"`
|
||||
}
|
||||
|
||||
// ScriptHash returns the hash of contract's script.
|
||||
func (c Contract) ScriptHash() util.Uint160 {
|
||||
return hash.Hash160(c.Script)
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler interface.
|
||||
func (c Contract) MarshalJSON() ([]byte, error) {
|
||||
var cc contract
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
||||
"github.com/CityOfZion/neo-go/pkg/internal/keytestcases"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -66,6 +67,13 @@ func TestContract_MarshalJSON(t *testing.T) {
|
|||
require.Error(t, json.Unmarshal(data, &c))
|
||||
}
|
||||
|
||||
func TestContract_ScriptHash(t *testing.T) {
|
||||
script := []byte{0, 1, 2, 3}
|
||||
c := &Contract{Script: script}
|
||||
|
||||
require.Equal(t, hash.Hash160(script), c.ScriptHash())
|
||||
}
|
||||
|
||||
func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) {
|
||||
if want, have := tk.Address, acc.Address; want != have {
|
||||
t.Fatalf("expected %s got %s", want, have)
|
||||
|
|
Loading…
Reference in a new issue