mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
Merge pull request #2072 from nspcc-dev/address-as-account-in-rpc-params
rpc/request: support passing accounts as addresses
This commit is contained in:
commit
5e26170b79
2 changed files with 22 additions and 3 deletions
|
@ -316,9 +316,14 @@ func (p *Param) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
case *signerWithWitnessAux:
|
||||
aux := *val
|
||||
accParam := Param{StringT, aux.Account}
|
||||
acc, err := accParam.GetUint160FromAddressOrHex()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Value = SignerWithWitness{
|
||||
Signer: transaction.Signer{
|
||||
Account: aux.Account,
|
||||
Account: acc,
|
||||
Scopes: aux.Scopes,
|
||||
AllowedContracts: aux.AllowedContracts,
|
||||
AllowedGroups: aux.AllowedGroups,
|
||||
|
@ -341,7 +346,7 @@ func (p *Param) UnmarshalJSON(data []byte) error {
|
|||
// signerWithWitnessAux is an auxiluary struct for JSON marshalling. We need it because of
|
||||
// DisallowUnknownFields JSON marshaller setting.
|
||||
type signerWithWitnessAux struct {
|
||||
Account util.Uint160 `json:"account"`
|
||||
Account string `json:"account"`
|
||||
Scopes transaction.WitnessScope `json:"scopes"`
|
||||
AllowedContracts []util.Uint160 `json:"allowedcontracts,omitempty"`
|
||||
AllowedGroups []*keys.PublicKey `json:"allowedgroups,omitempty"`
|
||||
|
@ -352,7 +357,7 @@ type signerWithWitnessAux struct {
|
|||
// MarshalJSON implements json.Unmarshaler interface.
|
||||
func (s *SignerWithWitness) MarshalJSON() ([]byte, error) {
|
||||
signer := &signerWithWitnessAux{
|
||||
Account: s.Account,
|
||||
Account: s.Account.StringLE(),
|
||||
Scopes: s.Scopes,
|
||||
AllowedContracts: s.AllowedContracts,
|
||||
AllowedGroups: s.AllowedGroups,
|
||||
|
|
|
@ -25,12 +25,15 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
|||
{"contract": "f84d6a337fbc3d3a201d41da99e86b479e7a2554", "name":"my_pretty_notification"},
|
||||
{"state": "HALT"},
|
||||
{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"},
|
||||
{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"},
|
||||
[{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}]]`
|
||||
contr, err := util.Uint160DecodeStringLE("f84d6a337fbc3d3a201d41da99e86b479e7a2554")
|
||||
require.NoError(t, err)
|
||||
name := "my_pretty_notification"
|
||||
accountHash, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569")
|
||||
require.NoError(t, err)
|
||||
addrHash, err := address.StringToUint160("NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag")
|
||||
require.NoError(t, err)
|
||||
expected := Params{
|
||||
{
|
||||
Type: StringT,
|
||||
|
@ -112,6 +115,15 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: SignerWithWitnessT,
|
||||
Value: SignerWithWitness{
|
||||
Signer: transaction.Signer{
|
||||
Account: addrHash,
|
||||
Scopes: transaction.Global,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: ArrayT,
|
||||
Value: []Param{
|
||||
|
@ -134,6 +146,8 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
|||
|
||||
msg = `[{"2": 3}]`
|
||||
require.Error(t, json.Unmarshal([]byte(msg), &ps))
|
||||
msg = `[{"account": "notanaccount", "scopes": "Global"}]`
|
||||
require.Error(t, json.Unmarshal([]byte(msg), &ps))
|
||||
}
|
||||
|
||||
func TestParamGetString(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue