-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpcsrv: add getrawnotarypool, getrawnotarytransaction handlers
`getrawnotarytransaction` takes a transaction hash and attempts to find the corresponding transaction in the notary requests mempool. It searches through all the verified main and fallback transactions. `getrawnotarypool` returns hashes of all the verified transactions, including both main and fallback transactions. Additionally add struct result.RawNotaryPool. Close #2951 Signed-off-by: Tatiana Nesterenko <[email protected]>
- Loading branch information
1 parent
a6ef3ff
commit 5396c94
Showing
4 changed files
with
299 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package result | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/util" | ||
) | ||
|
||
// RawNotaryPool represents a result of `getrawnotarypool` RPC call. | ||
// The structure consist of `Hashes`. `Hashes` field is a map, where key is | ||
// the hash of the main transaction and value is a slice of related fallback | ||
// transaction hashes. | ||
type RawNotaryPool struct { | ||
Hashes map[util.Uint256][]util.Uint256 | ||
} | ||
|
||
// rawNotaryPoolAux is an auxiliary struct for RawNotaryPool JSON marshalling. | ||
type rawNotaryPoolAux struct { | ||
Hashes map[string][]util.Uint256 `json:"hashes,omitempty"` | ||
} | ||
|
||
// MarshalJSON implements the json.Marshaler interface. | ||
func (p RawNotaryPool) MarshalJSON() ([]byte, error) { | ||
var aux rawNotaryPoolAux | ||
aux.Hashes = make(map[string][]util.Uint256, len(p.Hashes)) | ||
for main, fallbacks := range p.Hashes { | ||
mainBytes, err := main.MarshalJSON() | ||
if err != nil { | ||
return nil, err | ||
} | ||
aux.Hashes[string(mainBytes)] = fallbacks | ||
} | ||
return json.Marshal(aux) | ||
} | ||
|
||
// UnmarshalJSON implements the json.Unmarshaler interface. | ||
func (p *RawNotaryPool) UnmarshalJSON(data []byte) error { | ||
var ( | ||
aux rawNotaryPoolAux | ||
hashMain util.Uint256 | ||
) | ||
if err := json.Unmarshal(data, &aux); err != nil { | ||
return err | ||
} | ||
p.Hashes = make(map[util.Uint256][]util.Uint256, len(aux.Hashes)) | ||
for main, fallbacks := range aux.Hashes { | ||
if err := hashMain.UnmarshalJSON([]byte(main)); err != nil { | ||
return err | ||
} | ||
p.Hashes[hashMain] = fallbacks | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.