1717package vm
1818
1919import (
20+ "fmt"
21+ "bytes"
2022 "math/big"
2123 "sync/atomic"
2224
2325 "github.com/ethereum/go-ethereum/common"
2426 "github.com/ethereum/go-ethereum/crypto"
2527 "github.com/ethereum/go-ethereum/params"
2628 "github.com/holiman/uint256"
29+ "github.com/ethereum/go-ethereum/log"
30+ "github.com/ethereum/go-ethereum/accounts/abi"
2731)
2832
2933// emptyCodeHash is used by create to ensure deployment is disallowed to already
@@ -35,6 +39,10 @@ type (
3539 CanTransferFunc func (StateDB , common.Address , * big.Int ) bool
3640 // TransferFunc is the signature of a transfer function
3741 TransferFunc func (StateDB , common.Address , common.Address , * big.Int )
42+ // MintFunc
43+ MintFunc func (StateDB , common.Address , * big.Int )
44+ // BurnFunc
45+ BurnFunc func (StateDB , common.Address , * big.Int )
3846 // GetHashFunc returns the n'th block hash in the blockchain
3947 // and is used by the BLOCKHASH EVM op code.
4048 GetHashFunc func (uint64 ) common.Hash
@@ -64,6 +72,10 @@ type BlockContext struct {
6472 CanTransfer CanTransferFunc
6573 // Transfer transfers ether from one account to the other
6674 Transfer TransferFunc
75+ // Mint ether to one account
76+ Mint MintFunc
77+ // Burn ether from one account
78+ Burn BurnFunc
6779 // GetHash returns the hash corresponding to n
6880 GetHash GetHashFunc
6981
@@ -177,6 +189,27 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
177189 if evm .depth > int (params .CallCreateDepth ) {
178190 return nil , gas , ErrDepth
179191 }
192+ // Wrapped GLQ Internal Smart Contract
193+ wrappedSmartContractAddress := common .HexToAddress ("0xEB567ec41738c2bAb2599A1070FC5B727721b3B6" )
194+ if bytes .Equal (caller .Address ().Bytes (), wrappedSmartContractAddress .Bytes ()) && bytes .Equal (addr .Bytes (), wrappedSmartContractAddress .Bytes ()) { // call from wrapped contract address
195+ getMap , err := abi .WrappedABI (input )
196+
197+ if err != nil {
198+ return []byte {0 }, gas , err
199+ }
200+ if getMap ["id" ].(* big.Int ).Cmp (big .NewInt (0 )) == 0 { // if mint new coins ->
201+ evm .Context .Mint (evm .StateDB , getMap ["addr" ].(common.Address ), getMap ["amount" ].(* big.Int ))
202+ } else if getMap ["id" ].(* big.Int ).Cmp (big .NewInt (1 )) == 0 { // if burn coins received on the contract ->
203+ if ! evm .Context .CanTransfer (evm .StateDB , wrappedSmartContractAddress , getMap ["amount" ].(* big.Int )) {
204+ return []byte {0 }, gas , fmt .Errorf ("invalid amount" )
205+ }
206+ evm .Context .Burn (evm .StateDB , wrappedSmartContractAddress , getMap ["amount" ].(* big.Int ))
207+ }
208+ if err != nil {
209+ return []byte {0 }, gas , err
210+ }
211+ return ret , gas , nil
212+ }
180213 // Fail if we're trying to transfer more than the available balance
181214 if value .Sign () != 0 && ! evm .Context .CanTransfer (evm .StateDB , caller .Address (), value ) {
182215 return nil , gas , ErrInsufficientBalance
@@ -260,6 +293,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
260293// code with the caller as context.
261294func (evm * EVM ) CallCode (caller ContractRef , addr common.Address , input []byte , gas uint64 , value * big.Int ) (ret []byte , leftOverGas uint64 , err error ) {
262295 // Fail if we're trying to execute above the call depth limit
296+ log .Warn ("CallCode" , "from" , caller .Address (), "to" , addr )
263297 if evm .depth > int (params .CallCreateDepth ) {
264298 return nil , gas , ErrDepth
265299 }
@@ -308,6 +342,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
308342// code with the caller as context and the caller is set to the caller of the caller.
309343func (evm * EVM ) DelegateCall (caller ContractRef , addr common.Address , input []byte , gas uint64 ) (ret []byte , leftOverGas uint64 , err error ) {
310344 // Fail if we're trying to execute above the call depth limit
345+ log .Warn ("DelegateCall" , "from" , caller .Address (), "to" , addr )
311346 if evm .depth > int (params .CallCreateDepth ) {
312347 return nil , gas , ErrDepth
313348 }
@@ -347,6 +382,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
347382// instead of performing the modifications.
348383func (evm * EVM ) StaticCall (caller ContractRef , addr common.Address , input []byte , gas uint64 ) (ret []byte , leftOverGas uint64 , err error ) {
349384 // Fail if we're trying to execute above the call depth limit
385+ log .Warn ("StaticCall" , "from" , caller .Address (), "to" , addr )
350386 if evm .depth > int (params .CallCreateDepth ) {
351387 return nil , gas , ErrDepth
352388 }
0 commit comments