github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/neorpc/result/raw_notary_pool.go (about) 1 package result 2 3 import ( 4 "encoding/json" 5 "strings" 6 7 "github.com/nspcc-dev/neo-go/pkg/util" 8 ) 9 10 // RawNotaryPool represents a result of `getrawnotarypool` RPC call. 11 // The structure consist of `Hashes`. `Hashes` field is a map, where key is 12 // the hash of the main transaction and value is a slice of related fallback 13 // transaction hashes. 14 type RawNotaryPool struct { 15 Hashes map[util.Uint256][]util.Uint256 16 } 17 18 // rawNotaryPoolAux is an auxiliary struct for RawNotaryPool JSON marshalling. 19 type rawNotaryPoolAux struct { 20 Hashes map[string][]util.Uint256 `json:"hashes,omitempty"` 21 } 22 23 // MarshalJSON implements the json.Marshaler interface. 24 func (p RawNotaryPool) MarshalJSON() ([]byte, error) { 25 var aux rawNotaryPoolAux 26 aux.Hashes = make(map[string][]util.Uint256, len(p.Hashes)) 27 for main, fallbacks := range p.Hashes { 28 aux.Hashes["0x"+main.StringLE()] = fallbacks 29 } 30 return json.Marshal(aux) 31 } 32 33 // UnmarshalJSON implements the json.Unmarshaler interface. 34 func (p *RawNotaryPool) UnmarshalJSON(data []byte) error { 35 var aux rawNotaryPoolAux 36 if err := json.Unmarshal(data, &aux); err != nil { 37 return err 38 } 39 p.Hashes = make(map[util.Uint256][]util.Uint256, len(aux.Hashes)) 40 for main, fallbacks := range aux.Hashes { 41 hashMain, err := util.Uint256DecodeStringLE(strings.TrimPrefix(main, "0x")) 42 if err != nil { 43 return err 44 } 45 p.Hashes[hashMain] = fallbacks 46 } 47 return nil 48 }