Skip to content

Commit

Permalink
Merge branch 'feat/brioche-api' of https://github.com/wemixarchive/go…
Browse files Browse the repository at this point in the history
…-wemix into feat/brioche_devnet
  • Loading branch information
egonspace committed May 29, 2024
2 parents 2d63519 + c624228 commit 2ef3140
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 14 additions & 9 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,19 @@ func (api *PublicWemixAPI) HalvingSchedule() []*HalvingInfo {
return result
}

func (api *PublicWemixAPI) GetBriocheBlockReward(blockNumber *hexutil.Big) *hexutil.Big {
return (*hexutil.Big)(api.getBriocheBlockReward((*big.Int)(blockNumber)))
func (api *PublicWemixAPI) GetBriocheBlockReward(blockNumber rpc.BlockNumber) *hexutil.Big {
height := new(big.Int)
if blockNumber == rpc.LatestBlockNumber {
height.Set(api.e.BlockChain().CurrentHeader().Number)
} else if blockNumber == rpc.FinalizedBlockNumber {
height.Set(api.e.BlockChain().CurrentHeader().Number)
} else if blockNumber == rpc.PendingBlockNumber {
height.Set(api.e.miner.PendingBlock().Header().Number)
} else {
height.SetInt64(blockNumber.Int64())
}

return (*hexutil.Big)(api.getBriocheBlockReward(height))
}

func (api *PublicWemixAPI) getBriocheBlockReward(blockNumber *big.Int) *big.Int {
Expand All @@ -742,13 +753,7 @@ func (api *PublicWemixAPI) getBriocheBlockReward(blockNumber *big.Int) *big.Int
}
wemixInfo := *wemixInfoPtr
config := api.e.BlockChain().Config()

height := new(big.Int)
if blockNumber == nil {
height.Set(api.e.BlockChain().CurrentHeader().Number)
} else {
height.Set(blockNumber)
}
height := new(big.Int).Set(blockNumber)

if config.IsBrioche(height) {
return config.Brioche.GetBriocheBlockReward(wemixInfo["defaultBriocheBlockReward"].(*big.Int), height)
Expand Down
3 changes: 1 addition & 2 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,7 @@ web3._extend({
new web3._extend.Method({
name: 'getBriocheBlockReward',
call: 'wemix_getBriocheBlockReward',
params: 1,
inputFormatter: [null]
params: 1
})
],
properties:
Expand Down

0 comments on commit 2ef3140

Please sign in to comment.