aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-07-29 12:01:05 -0400
committerDeterminant <tederminant@gmail.com>2020-07-29 12:01:05 -0400
commit1f49826de2bb8bb4f5f99f69fd2beb039b1172d9 (patch)
tree4db4d3687f89f55c42898ba12e59e2236da03558 /core
parent67ae6a33a4bfd74dad0a043f07f91647d34cff8d (diff)
clean upmulti-coin
Diffstat (limited to 'core')
-rw-r--r--core/state_transition.go8
-rw-r--r--core/types/gen_tx_json.go12
-rw-r--r--core/types/transaction.go33
-rw-r--r--core/vm/interpreter.go14
4 files changed, 21 insertions, 46 deletions
diff --git a/core/state_transition.go b/core/state_transition.go
index 7a48597..de7488e 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -55,8 +55,6 @@ type StateTransition struct {
gasPrice *big.Int
initialGas uint64
value *big.Int
- coinID *common.Hash
- value2 *big.Int
data []byte
state vm.StateDB
evm *vm.EVM
@@ -71,8 +69,6 @@ type Message interface {
GasPrice() *big.Int
Gas() uint64
Value() *big.Int
- CoinID() *common.Hash
- Value2() *big.Int
Nonce() uint64
CheckNonce() bool
@@ -124,8 +120,6 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
msg: msg,
gasPrice: msg.GasPrice(),
value: msg.Value(),
- coinID: msg.CoinID(),
- value2: msg.Value2(),
data: msg.Data(),
state: evm.StateDB,
}
@@ -221,7 +215,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
} else {
// Increment the nonce for the next transaction
st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
- ret, st.gas, vmerr = evm.CallExpert(sender, st.to(), st.data, st.gas, st.value, st.coinID, st.value2)
+ ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
if vmerr != nil {
log.Debug("VM returned with error", "err", vmerr)
diff --git a/core/types/gen_tx_json.go b/core/types/gen_tx_json.go
index dd0d069..0410632 100644
--- a/core/types/gen_tx_json.go
+++ b/core/types/gen_tx_json.go
@@ -21,8 +21,6 @@ func (t txdata) MarshalJSON() ([]byte, error) {
GasLimit hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
- CoinID *common.Hash `json:"coinid" rlp:"nil"`
- Amount2 *hexutil.Big `json:"value2" rlp:"nil"`
Payload hexutil.Bytes `json:"input" gencodec:"required"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
@@ -35,8 +33,6 @@ func (t txdata) MarshalJSON() ([]byte, error) {
enc.GasLimit = hexutil.Uint64(t.GasLimit)
enc.Recipient = t.Recipient
enc.Amount = (*hexutil.Big)(t.Amount)
- enc.CoinID = t.CoinID
- enc.Amount2 = (*hexutil.Big)(t.Amount2)
enc.Payload = t.Payload
enc.V = (*hexutil.Big)(t.V)
enc.R = (*hexutil.Big)(t.R)
@@ -53,8 +49,6 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
GasLimit *hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
- CoinID *common.Hash `json:"coinid" rlp:"nil"`
- Amount2 *hexutil.Big `json:"value2" rlp:"nil"`
Payload *hexutil.Bytes `json:"input" gencodec:"required"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
@@ -84,12 +78,6 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
return errors.New("missing required field 'value' for txdata")
}
t.Amount = (*big.Int)(dec.Amount)
- if dec.CoinID != nil {
- t.CoinID = dec.CoinID
- }
- if dec.Amount2 != nil {
- t.Amount2 = (*big.Int)(dec.Amount2)
- }
if dec.Payload == nil {
return errors.New("missing required field 'input' for txdata")
}
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 858b443..d9ada38 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -49,8 +49,6 @@ type txdata struct {
GasLimit uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation
Amount *big.Int `json:"value" gencodec:"required"`
- CoinID *common.Hash `json:"coinid" rlp:"nil"`
- Amount2 *big.Int `json:"value2" rlp:"nil"`
Payload []byte `json:"input" gencodec:"required"`
// Signature values
@@ -67,8 +65,6 @@ type txdataMarshaling struct {
Price *hexutil.Big
GasLimit hexutil.Uint64
Amount *hexutil.Big
- CoinID *common.Hash
- Amount2 *hexutil.Big
Payload hexutil.Bytes
V *hexutil.Big
R *hexutil.Big
@@ -92,8 +88,6 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
Recipient: to,
Payload: data,
Amount: new(big.Int),
- CoinID: nil,
- Amount2: new(big.Int),
GasLimit: gasLimit,
Price: new(big.Int),
V: new(big.Int),
@@ -110,11 +104,6 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
return &Transaction{data: d}
}
-func (tx *Transaction) SetMultiCoinValue(coinID *common.Hash, amount *big.Int) {
- tx.data.CoinID = coinID
- tx.data.Amount2.Set(amount)
-}
-
// ChainId returns which chain id this transaction was signed for (if at all)
func (tx *Transaction) ChainId() *big.Int {
return deriveChainId(tx.data.V)
@@ -183,14 +172,12 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
return nil
}
-func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) }
-func (tx *Transaction) Gas() uint64 { return tx.data.GasLimit }
-func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) }
-func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) }
-func (tx *Transaction) CoinID() *common.Hash { return tx.data.CoinID }
-func (tx *Transaction) Value2() *big.Int { return new(big.Int).Set(tx.data.Amount2) }
-func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
-func (tx *Transaction) CheckNonce() bool { return true }
+func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) }
+func (tx *Transaction) Gas() uint64 { return tx.data.GasLimit }
+func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) }
+func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) }
+func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
+func (tx *Transaction) CheckNonce() bool { return true }
// To returns the recipient address of the transaction.
// It returns nil if the transaction is a contract creation.
@@ -237,8 +224,6 @@ func (tx *Transaction) AsMessage(s Signer) (Message, error) {
gasPrice: new(big.Int).Set(tx.data.Price),
to: tx.data.Recipient,
amount: tx.data.Amount,
- coinID: tx.data.CoinID,
- amount2: tx.data.Amount2,
data: tx.data.Payload,
checkNonce: true,
}
@@ -405,8 +390,6 @@ type Message struct {
from common.Address
nonce uint64
amount *big.Int
- coinID *common.Hash
- amount2 *big.Int
gasLimit uint64
gasPrice *big.Int
data []byte
@@ -419,8 +402,6 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
to: to,
nonce: nonce,
amount: amount,
- coinID: nil,
- amount2: big.NewInt(0),
gasLimit: gasLimit,
gasPrice: gasPrice,
data: data,
@@ -432,8 +413,6 @@ func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) Value() *big.Int { return m.amount }
-func (m Message) CoinID() *common.Hash { return m.coinID }
-func (m Message) Value2() *big.Int { return m.amount2 }
func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go
index 3d388d6..e23896a 100644
--- a/core/vm/interpreter.go
+++ b/core/vm/interpreter.go
@@ -26,6 +26,13 @@ import (
"github.com/ava-labs/go-ethereum/log"
)
+var (
+ BuiltinAddr = common.Address{
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ }
+)
+
// Config are the configuration options for the Interpreter
type Config struct {
Debug bool // Enables debugging
@@ -131,6 +138,13 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
// considered a revert-and-consume-all-gas operation except for
// errExecutionReverted which means revert-and-keep-gas-left.
func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) {
+ if contract.Address() == BuiltinAddr {
+ self := AccountRef(contract.Caller())
+ if _, ok := contract.caller.(*Contract); ok {
+ contract = contract.AsDelegate()
+ }
+ contract.self = self
+ }
if in.intPool == nil {
in.intPool = poolOfIntPools.get()
defer func() {