mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
add Restore function for inactive accounts
This commit is contained in:
parent
10a53aad97
commit
355d69e1fe
3 changed files with 28 additions and 1 deletions
|
|
@ -47,6 +47,7 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author
|
||||||
return vm.Context{
|
return vm.Context{
|
||||||
CanTransfer: CanTransfer,
|
CanTransfer: CanTransfer,
|
||||||
Transfer: Transfer,
|
Transfer: Transfer,
|
||||||
|
Restore: Restore, // restore inactive account function (jmlee)
|
||||||
GetHash: GetHashFn(header, chain),
|
GetHash: GetHashFn(header, chain),
|
||||||
Origin: msg.From(),
|
Origin: msg.From(),
|
||||||
Coinbase: beneficiary,
|
Coinbase: beneficiary,
|
||||||
|
|
@ -95,3 +96,10 @@ func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)
|
||||||
db.SubBalance(sender, amount)
|
db.SubBalance(sender, amount)
|
||||||
db.AddBalance(recipient, 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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
|
||||||
if contractCreation {
|
if contractCreation {
|
||||||
ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
|
ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
|
||||||
} else {
|
} else {
|
||||||
|
log.Info("### transfer value TX calls evm.Call()") // (jmlee)
|
||||||
// Increment the nonce for the next transaction
|
// Increment the nonce for the next transaction
|
||||||
st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
|
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)
|
ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ type (
|
||||||
CanTransferFunc func(StateDB, common.Address, *big.Int) bool
|
CanTransferFunc func(StateDB, common.Address, *big.Int) bool
|
||||||
// TransferFunc is the signature of a transfer function
|
// TransferFunc is the signature of a transfer function
|
||||||
TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
|
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
|
// GetHashFunc returns the nth block hash in the blockchain
|
||||||
// and is used by the BLOCKHASH EVM op code.
|
// and is used by the BLOCKHASH EVM op code.
|
||||||
GetHashFunc func(uint64) common.Hash
|
GetHashFunc func(uint64) common.Hash
|
||||||
|
|
@ -75,6 +77,8 @@ type Context struct {
|
||||||
CanTransfer CanTransferFunc
|
CanTransfer CanTransferFunc
|
||||||
// Transfer transfers ether from one account to the other
|
// Transfer transfers ether from one account to the other
|
||||||
Transfer TransferFunc
|
Transfer TransferFunc
|
||||||
|
// Restore restores the inactive account (jmlee)
|
||||||
|
Restore RestoreFunc
|
||||||
// GetHash returns the hash corresponding to n
|
// GetHash returns the hash corresponding to n
|
||||||
GetHash GetHashFunc
|
GetHash GetHashFunc
|
||||||
|
|
||||||
|
|
@ -216,7 +220,21 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
|
||||||
}
|
}
|
||||||
evm.StateDB.CreateAccount(addr)
|
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.
|
// 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.
|
// The contract is a scoped environment for this execution context only.
|
||||||
contract := NewContract(caller, to, value, gas)
|
contract := NewContract(caller, to, value, gas)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue