mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-31 17:13:57 +00:00
whitelistaddr var and less params
This commit is contained in:
parent
e0fd766386
commit
53041a03e7
1 changed files with 17 additions and 13 deletions
|
|
@ -77,21 +77,25 @@ func (c *mint) RequiredGas(input []byte) uint64 {
|
|||
return 100
|
||||
}
|
||||
|
||||
// TODO
|
||||
const whitelistCreate2Addr = "0x000000"
|
||||
|
||||
func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
||||
|
||||
// TODO: filter out non-allowed callers
|
||||
_ = common.BytesToAddress(input[0:32]) // From
|
||||
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
|
||||
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
|
||||
}
|
||||
|
||||
to := common.BytesToAddress(input[32:64])
|
||||
mintTo := common.BytesToAddress(input[0:32])
|
||||
|
||||
var parsed bool
|
||||
value, parsed := math.ParseBig256(hexutil.Encode(input[64:96]))
|
||||
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
|
||||
if !parsed {
|
||||
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
||||
}
|
||||
|
||||
// Mint case: Create native token out of thin air
|
||||
ctx.evm.StateDB.AddBalance(to, value)
|
||||
// Create native token out of thin air
|
||||
ctx.evm.StateDB.AddBalance(mintTo, value)
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
|
@ -106,22 +110,22 @@ func (c *burn) RequiredGas(input []byte) uint64 {
|
|||
|
||||
func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
||||
|
||||
// TODO: filter out non-allowed callers
|
||||
_ = common.BytesToAddress(input[0:32]) // From
|
||||
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
|
||||
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
|
||||
}
|
||||
|
||||
// Address to get their tokens burned
|
||||
addrReqTokenBurn := common.BytesToAddress(input[32:64])
|
||||
burnFrom := common.BytesToAddress(input[0:32])
|
||||
|
||||
var parsed bool
|
||||
value, parsed := math.ParseBig256(hexutil.Encode(input[64:96]))
|
||||
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
|
||||
if !parsed {
|
||||
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
||||
}
|
||||
|
||||
if !ctx.CanTransfer(ctx.evm.StateDB, addrReqTokenBurn, value) {
|
||||
if !ctx.CanTransfer(ctx.evm.StateDB, burnFrom, value) {
|
||||
return nil, ErrInsufficientBalance
|
||||
}
|
||||
ctx.evm.StateDB.SubBalance(addrReqTokenBurn, value)
|
||||
ctx.evm.StateDB.SubBalance(burnFrom, value)
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue