On developing a custom geth fork there is the need to call a specific hardcoded smart contract when ETH transfer occur. This is not an Ethereum normal behaviour but a new feature we want to implement on the fork. The calling of the contract will be done inside the very transaction that triggers the whole process, so creating a new transaction to call the contract is not an option. The atomic transaction must include the internal call of the contract (this special contract will have a hardcoded address all the time).
The main change of the code in this fork will be at https://github.com/ethereum/go-ethereum/blob/master/core/evm.go#L93
// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {
db.SubBalance(sender, amount)
db.AddBalance(recipient, amount)
}
to something like this:
// Transfer is performed on an ERC-20 contract
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {
mySpecialContract.transfer(recipient, amount {from: sender})
}
So, questions are:
Is that possible to do?
Should I define the "mySpecialContract" object first? How?
How can GoLang call an specific method of a given contract?
Having the address of the contract, the method name and parameters (the whole ABI actually) is there any example code to invoke this kind of methods?
By the way, I feel like there is a function on geth code that could do that: core\vm\evm.go(43)
// run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) {
Someone can confirm? Thx!