forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b27b146
commit 7f604c9
Showing
9 changed files
with
170 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package core | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/blockcypher/go-ethereum/common" | ||
"github.com/blockcypher/go-ethereum/core/types" | ||
"github.com/blockcypher/go-ethereum/core/vm" | ||
) | ||
|
||
// Implementation of evm.InternalTxListener | ||
|
||
type InternalTxWatcher struct { | ||
internals types.InternalTransactions | ||
} | ||
|
||
func NewInternalTxWatcher() *InternalTxWatcher { | ||
return &InternalTxWatcher{ | ||
internals: make(types.InternalTransactions, 0), | ||
} | ||
} | ||
|
||
// Public API: for users | ||
func (self *InternalTxWatcher) SetParentHash(ph common.Hash) { | ||
for i := range self.internals { | ||
self.internals[i].ParentHash = ph | ||
} | ||
} | ||
|
||
func (self *InternalTxWatcher) InternalTransactions() types.InternalTransactions { | ||
return self.internals | ||
} | ||
|
||
// Public API: For interfacing with EVM | ||
func (self *InternalTxWatcher) RegisterCall(nonce uint64, gasPrice *big.Int, gas uint64, srcAddr, dstAddr common.Address, value *big.Int, data []byte, depth uint64) { | ||
self.internals = append(self.internals, | ||
types.NewInternalTransaction(nonce, gasPrice, gas, | ||
srcAddr, dstAddr, value, data, depth, self.index(), "call")) | ||
} | ||
|
||
func (self *InternalTxWatcher) RegisterStaticCall(nonce uint64, gasPrice *big.Int, gas uint64, srcAddr, dstAddr common.Address, data []byte, depth uint64) { | ||
|
||
self.internals = append(self.internals, | ||
types.NewInternalTransaction(nonce, gasPrice, gas, | ||
srcAddr, dstAddr, big.NewInt(0), data, depth, self.index(), | ||
"staticcall")) | ||
} | ||
|
||
func (self *InternalTxWatcher) RegisterCallCode(nonce uint64, gasPrice *big.Int, gas uint64, contractAddr common.Address, value *big.Int, data []byte, depth uint64) { | ||
self.internals = append(self.internals, | ||
types.NewInternalTransaction(nonce, gasPrice, gas, | ||
contractAddr, contractAddr, value, data, depth, self.index(), | ||
"call")) | ||
} | ||
|
||
func (self *InternalTxWatcher) RegisterCreate(nonce uint64, gasPrice *big.Int, gas uint64, srcAddr, newContractAddr common.Address, value *big.Int, data []byte, depth uint64) { | ||
self.internals = append(self.internals, | ||
types.NewInternalTransaction(nonce, gasPrice, gas, | ||
srcAddr, newContractAddr, value, data, depth, self.index(), | ||
"create")) | ||
} | ||
|
||
func (self *InternalTxWatcher) RegisterDelegateCall(nonce uint64, gasPrice *big.Int, gas uint64, callerAddr common.Address, value *big.Int, data []byte, depth uint64) { | ||
self.internals = append(self.internals, | ||
types.NewInternalTransaction(nonce, gasPrice, gas, | ||
callerAddr, callerAddr, value, data, depth, self.index(), "call")) | ||
} | ||
|
||
func (self *InternalTxWatcher) RegisterSuicide(nonce uint64, gasPrice *big.Int, gas uint64, contractAddr, creatorAddr common.Address, remainingValue *big.Int, depth uint64) { | ||
self.internals = append(self.internals, | ||
types.NewInternalTransaction(nonce, gasPrice, gas, | ||
contractAddr, creatorAddr, remainingValue, | ||
append([]byte{byte(vm.SELFDESTRUCT)}, creatorAddr[:]...), | ||
depth, self.index(), "suicide")) | ||
} | ||
|
||
// Utilities | ||
func (self *InternalTxWatcher) index() uint64 { | ||
return uint64(len(self.internals)) | ||
} | ||
|
||
func toBigInt(g uint64) *big.Int { | ||
return big.NewInt(0).SetUint64(g) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package types | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/blockcypher/go-ethereum/common" | ||
) | ||
|
||
type InternalTransaction struct { | ||
Transaction Transaction | ||
|
||
Sender common.Address | ||
ParentHash common.Hash | ||
Depth uint64 | ||
Index uint64 | ||
Note string | ||
Rejected bool | ||
} | ||
|
||
type InternalTransactions []*InternalTransaction | ||
|
||
func NewInternalTransaction(accountNonce uint64, price *big.Int, | ||
gasLimit uint64, sender common.Address, | ||
recipient common.Address, amount *big.Int, payload []byte, | ||
depth, index uint64, note string) *InternalTransaction { | ||
|
||
tx := NewTransaction(accountNonce, recipient, amount, gasLimit, price, payload) | ||
var h common.Hash | ||
return &InternalTransaction{*tx, sender, h, depth, index, note, false} | ||
} | ||
|
||
func (tx *InternalTransaction) Reject() { | ||
tx.Rejected = true | ||
} | ||
|
||
func (tx *InternalTransaction) Hash() common.Hash { | ||
rej := byte(0) | ||
if tx.Rejected { | ||
rej = byte(1) | ||
} | ||
|
||
data := []interface{}{ | ||
tx.Transaction.Nonce(), | ||
tx.ParentHash, | ||
tx.Sender, | ||
*tx.Transaction.To(), | ||
tx.Transaction.Value(), | ||
tx.Transaction.GasPrice(), | ||
tx.Transaction.Gas(), | ||
tx.Transaction.Data(), | ||
tx.Note, | ||
tx.Depth, | ||
tx.Index, | ||
rej, | ||
} | ||
return rlpHash(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters