mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 16:03:45 +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
|
return 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
const whitelistCreate2Addr = "0x000000"
|
||||||
|
|
||||||
func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
||||||
|
|
||||||
// TODO: filter out non-allowed callers
|
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
|
||||||
_ = common.BytesToAddress(input[0:32]) // From
|
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
|
var parsed bool
|
||||||
value, parsed := math.ParseBig256(hexutil.Encode(input[64:96]))
|
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
|
||||||
if !parsed {
|
if !parsed {
|
||||||
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
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
|
// Create native token out of thin air
|
||||||
ctx.evm.StateDB.AddBalance(to, value)
|
ctx.evm.StateDB.AddBalance(mintTo, value)
|
||||||
|
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
@ -106,22 +110,22 @@ func (c *burn) RequiredGas(input []byte) uint64 {
|
||||||
|
|
||||||
func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
||||||
|
|
||||||
// TODO: filter out non-allowed callers
|
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
|
||||||
_ = common.BytesToAddress(input[0:32]) // From
|
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
|
||||||
|
}
|
||||||
|
|
||||||
// Address to get their tokens burned
|
burnFrom := common.BytesToAddress(input[0:32])
|
||||||
addrReqTokenBurn := common.BytesToAddress(input[32:64])
|
|
||||||
|
|
||||||
var parsed bool
|
var parsed bool
|
||||||
value, parsed := math.ParseBig256(hexutil.Encode(input[64:96]))
|
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
|
||||||
if !parsed {
|
if !parsed {
|
||||||
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
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
|
return nil, ErrInsufficientBalance
|
||||||
}
|
}
|
||||||
ctx.evm.StateDB.SubBalance(addrReqTokenBurn, value)
|
ctx.evm.StateDB.SubBalance(burnFrom, value)
|
||||||
|
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue