feat: add genesis + mempool chain actions (106 total)
- blockchain.chain.genesis — returns genesis block hash, timestamp, network detection (mainnet/testnet/unknown) - blockchain.chain.mempool — returns tx pool size (empty for Go node) Total Core Actions: 106. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
e9ad1b1fc6
commit
5c38716303
1 changed files with 29 additions and 0 deletions
29
actions.go
29
actions.go
|
|
@ -37,6 +37,8 @@ func RegisterActions(c *core.Core, ch *chain.Chain) {
|
|||
c.Action("blockchain.chain.difficulty", makeChainDifficulty(ch))
|
||||
c.Action("blockchain.chain.transaction", makeChainTransaction(ch))
|
||||
c.Action("blockchain.chain.peers", makeChainPeers(ch))
|
||||
c.Action("blockchain.chain.genesis", makeChainGenesis(ch))
|
||||
c.Action("blockchain.chain.mempool", makeChainMempool(ch))
|
||||
|
||||
// Aliases
|
||||
c.Action("blockchain.alias.list", makeAliasList(ch))
|
||||
|
|
@ -202,6 +204,33 @@ func makeChainPeers(ch *chain.Chain) core.ActionHandler {
|
|||
}
|
||||
}
|
||||
|
||||
func makeChainGenesis(ch *chain.Chain) core.ActionHandler {
|
||||
return func(ctx context.Context, opts core.Options) core.Result {
|
||||
blk, meta, err := ch.GetBlockByHeight(0)
|
||||
if err != nil {
|
||||
return core.Result{Value: map[string]interface{}{
|
||||
"hash": chain.GenesisHash, "height": uint64(0),
|
||||
}, OK: true}
|
||||
}
|
||||
return core.Result{Value: map[string]interface{}{
|
||||
"hash": meta.Hash.String(),
|
||||
"height": uint64(0),
|
||||
"timestamp": blk.Timestamp,
|
||||
"network": chain.DetectNetwork(meta.Hash.String()),
|
||||
}, OK: true}
|
||||
}
|
||||
}
|
||||
|
||||
func makeChainMempool(ch *chain.Chain) core.ActionHandler {
|
||||
return func(ctx context.Context, opts core.Options) core.Result {
|
||||
return core.Result{Value: map[string]interface{}{
|
||||
"size": 0,
|
||||
"transactions": []interface{}{},
|
||||
"note": "Go node does not maintain a local mempool",
|
||||
}, OK: true}
|
||||
}
|
||||
}
|
||||
|
||||
func makeAliasList(ch *chain.Chain) core.ActionHandler {
|
||||
return func(ctx context.Context, opts core.Options) core.Result {
|
||||
return core.Result{Value: ch.GetAllAliases(), OK: true}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue