wallet: add signature check contracts to new accounts

This commit is contained in:
Evgenii Stratonikov 2020-02-20 13:28:35 +03:00
parent eacea8bff5
commit 5a727cabf8
2 changed files with 24 additions and 3 deletions

View file

@ -4,9 +4,11 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"github.com/CityOfZion/neo-go/pkg/crypto/hash" "github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
"github.com/CityOfZion/neo-go/pkg/smartcontract"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
@ -50,7 +52,7 @@ type Contract struct {
Script []byte `json:"script"` Script []byte `json:"script"`
// A list of parameters used deploying this contract. // A list of parameters used deploying this contract.
Parameters []interface{} `json:"parameters"` Parameters []contractParam `json:"parameters"`
// Indicates whether the contract has been deployed to the blockchain. // Indicates whether the contract has been deployed to the blockchain.
Deployed bool `json:"deployed"` Deployed bool `json:"deployed"`
@ -62,12 +64,17 @@ type contract struct {
Script string `json:"script"` Script string `json:"script"`
// A list of parameters used deploying this contract. // A list of parameters used deploying this contract.
Parameters []interface{} `json:"parameters"` Parameters []contractParam `json:"parameters"`
// Indicates whether the contract has been deployed to the blockchain. // Indicates whether the contract has been deployed to the blockchain.
Deployed bool `json:"deployed"` Deployed bool `json:"deployed"`
} }
type contractParam struct {
Name string `json:"name"`
Type smartcontract.ParamType `json:"type"`
}
// ScriptHash returns the hash of contract's script. // ScriptHash returns the hash of contract's script.
func (c Contract) ScriptHash() util.Uint160 { func (c Contract) ScriptHash() util.Uint160 {
return hash.Hash160(c.Script) return hash.Hash160(c.Script)
@ -181,7 +188,21 @@ func newAccountFromPrivateKey(p *keys.PrivateKey) *Account {
privateKey: p, privateKey: p,
Address: pubAddr, Address: pubAddr,
wif: wif, wif: wif,
Contract: &Contract{
Script: pubKey.GetVerificationScript(),
Parameters: getContractParams(1),
},
} }
return a return a
} }
func getContractParams(n int) []contractParam {
params := make([]contractParam, n)
for i := range params {
params[i].Name = fmt.Sprintf("parameter%d", i)
params[i].Type = smartcontract.SignatureType
}
return params
}

View file

@ -65,7 +65,7 @@ func TestNewAccountFromEncryptedWIF(t *testing.T) {
func TestContract_MarshalJSON(t *testing.T) { func TestContract_MarshalJSON(t *testing.T) {
var c Contract var c Contract
data := []byte(`{"script":"0102","parameters":[1],"deployed":false}`) data := []byte(`{"script":"0102","parameters":[{"name":"name0", "type":"Signature"}],"deployed":false}`)
require.NoError(t, json.Unmarshal(data, &c)) require.NoError(t, json.Unmarshal(data, &c))
require.Equal(t, []byte{1, 2}, c.Script) require.Equal(t, []byte{1, 2}, c.Script)