rpc/request: support passing accounts as addresses
Turns out, it's completely legal in C#, see neo-project/neo#2543.
This commit is contained in:
parent
05cb6586a6
commit
a617390185
2 changed files with 22 additions and 3 deletions
|
@ -316,9 +316,14 @@ func (p *Param) UnmarshalJSON(data []byte) error {
|
||||||
}
|
}
|
||||||
case *signerWithWitnessAux:
|
case *signerWithWitnessAux:
|
||||||
aux := *val
|
aux := *val
|
||||||
|
accParam := Param{StringT, aux.Account}
|
||||||
|
acc, err := accParam.GetUint160FromAddressOrHex()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
p.Value = SignerWithWitness{
|
p.Value = SignerWithWitness{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: aux.Account,
|
Account: acc,
|
||||||
Scopes: aux.Scopes,
|
Scopes: aux.Scopes,
|
||||||
AllowedContracts: aux.AllowedContracts,
|
AllowedContracts: aux.AllowedContracts,
|
||||||
AllowedGroups: aux.AllowedGroups,
|
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
|
// signerWithWitnessAux is an auxiluary struct for JSON marshalling. We need it because of
|
||||||
// DisallowUnknownFields JSON marshaller setting.
|
// DisallowUnknownFields JSON marshaller setting.
|
||||||
type signerWithWitnessAux struct {
|
type signerWithWitnessAux struct {
|
||||||
Account util.Uint160 `json:"account"`
|
Account string `json:"account"`
|
||||||
Scopes transaction.WitnessScope `json:"scopes"`
|
Scopes transaction.WitnessScope `json:"scopes"`
|
||||||
AllowedContracts []util.Uint160 `json:"allowedcontracts,omitempty"`
|
AllowedContracts []util.Uint160 `json:"allowedcontracts,omitempty"`
|
||||||
AllowedGroups []*keys.PublicKey `json:"allowedgroups,omitempty"`
|
AllowedGroups []*keys.PublicKey `json:"allowedgroups,omitempty"`
|
||||||
|
@ -352,7 +357,7 @@ type signerWithWitnessAux struct {
|
||||||
// MarshalJSON implements json.Unmarshaler interface.
|
// MarshalJSON implements json.Unmarshaler interface.
|
||||||
func (s *SignerWithWitness) MarshalJSON() ([]byte, error) {
|
func (s *SignerWithWitness) MarshalJSON() ([]byte, error) {
|
||||||
signer := &signerWithWitnessAux{
|
signer := &signerWithWitnessAux{
|
||||||
Account: s.Account,
|
Account: s.Account.StringLE(),
|
||||||
Scopes: s.Scopes,
|
Scopes: s.Scopes,
|
||||||
AllowedContracts: s.AllowedContracts,
|
AllowedContracts: s.AllowedContracts,
|
||||||
AllowedGroups: s.AllowedGroups,
|
AllowedGroups: s.AllowedGroups,
|
||||||
|
|
|
@ -25,12 +25,15 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
||||||
{"contract": "f84d6a337fbc3d3a201d41da99e86b479e7a2554", "name":"my_pretty_notification"},
|
{"contract": "f84d6a337fbc3d3a201d41da99e86b479e7a2554", "name":"my_pretty_notification"},
|
||||||
{"state": "HALT"},
|
{"state": "HALT"},
|
||||||
{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"},
|
{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"},
|
||||||
|
{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"},
|
||||||
[{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}]]`
|
[{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}]]`
|
||||||
contr, err := util.Uint160DecodeStringLE("f84d6a337fbc3d3a201d41da99e86b479e7a2554")
|
contr, err := util.Uint160DecodeStringLE("f84d6a337fbc3d3a201d41da99e86b479e7a2554")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
name := "my_pretty_notification"
|
name := "my_pretty_notification"
|
||||||
accountHash, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569")
|
accountHash, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
addrHash, err := address.StringToUint160("NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag")
|
||||||
|
require.NoError(t, err)
|
||||||
expected := Params{
|
expected := Params{
|
||||||
{
|
{
|
||||||
Type: StringT,
|
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,
|
Type: ArrayT,
|
||||||
Value: []Param{
|
Value: []Param{
|
||||||
|
@ -134,6 +146,8 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
||||||
|
|
||||||
msg = `[{"2": 3}]`
|
msg = `[{"2": 3}]`
|
||||||
require.Error(t, json.Unmarshal([]byte(msg), &ps))
|
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) {
|
func TestParamGetString(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue