diff --git a/core/evm.go b/core/evm.go index 13949c9233..1fd4849622 100644 --- a/core/evm.go +++ b/core/evm.go @@ -47,6 +47,7 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author return vm.Context{ CanTransfer: CanTransfer, Transfer: Transfer, + Restore: Restore, // restore inactive account function (jmlee) GetHash: GetHashFn(header, chain), Origin: msg.From(), Coinbase: beneficiary, @@ -95,3 +96,10 @@ func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int) db.SubBalance(sender, amount) db.AddBalance(recipient, amount) } + +// Restore restores the inactive account (jmlee) +func Restore(db vm.StateDB, inactiveAddr common.Address, amount *big.Int) { + bal := db.GetBalance(inactiveAddr) + db.SubBalance(inactiveAddr, bal) + db.AddBalance(inactiveAddr, amount) +} diff --git a/core/state_transition.go b/core/state_transition.go index 39b17ed48c..82e90a2b13 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -208,6 +208,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo if contractCreation { ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value) } else { + log.Info("### transfer value TX calls evm.Call()") // (jmlee) // Increment the nonce for the next transaction st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1) ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value) diff --git a/core/vm/evm.go b/core/vm/evm.go index 16cd0c896d..a02023f50b 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -35,6 +35,8 @@ type ( CanTransferFunc func(StateDB, common.Address, *big.Int) bool // TransferFunc is the signature of a transfer function TransferFunc func(StateDB, common.Address, common.Address, *big.Int) + // RestoreFunc is the signature of a restore function (jmlee) + RestoreFunc func(StateDB, common.Address, *big.Int) // GetHashFunc returns the nth block hash in the blockchain // and is used by the BLOCKHASH EVM op code. GetHashFunc func(uint64) common.Hash @@ -75,6 +77,8 @@ type Context struct { CanTransfer CanTransferFunc // Transfer transfers ether from one account to the other Transfer TransferFunc + // Restore restores the inactive account (jmlee) + Restore RestoreFunc // GetHash returns the hash corresponding to n GetHash GetHashFunc @@ -216,7 +220,21 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas } evm.StateDB.CreateAccount(addr) } - evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) + + // old version (jmlee) + //evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) + // new version (jmlee) + if addr == common.HexToAddress("0x1111111111111111111111111111111111111111") { + // restoration tx + inactiveAddr := common.HexToAddress("0x12345") // temp value for test + evm.StateDB.CreateAccount(inactiveAddr) // temp setting for test + amount := big.NewInt(12345) // temp value for test + evm.Restore(evm.StateDB, inactiveAddr, amount) + } else { + // value transfer tx + evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) + } + // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. contract := NewContract(caller, to, value, gas)