Skip to content

Commit

Permalink
Merge pull request ethereum#14 from OffchainLabs/get-pool-nonce
Browse files Browse the repository at this point in the history
Implement GetPoolNonce & GetLogs
  • Loading branch information
PlasmaPower authored Nov 5, 2021
2 parents 3c6c46a + f81705d commit 99434bf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ type callMsg struct {
ethereum.CallMsg
}

func (m callMsg) UnderlyingTransaction() *types.Transaction { return nil }
func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) IsFake() bool { return true }
Expand Down
21 changes: 18 additions & 3 deletions arbitrum/apibackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func (a *APIBackend) CurrentBlock() *types.Block {
}

func (a *APIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) {
if number == rpc.LatestBlockNumber || number == rpc.PendingBlockNumber {
return a.blockChain().CurrentBlock(), nil
}
return a.blockChain().GetBlockByNumber(uint64(number.Int64())), nil
}

Expand Down Expand Up @@ -220,7 +223,11 @@ func (a *APIBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction {
}

func (a *APIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) {
panic("not implemented") // TODO: Implement
stateDB, err := a.blockChain().State()
if err != nil {
return 0, err
}
return stateDB.GetNonce(addr), nil
}

func (a *APIBackend) Stats() (pending int, queued int) {
Expand All @@ -241,11 +248,19 @@ func (a *APIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subs

// Filter API
func (a *APIBackend) BloomStatus() (uint64, uint64) {
panic("not implemented") // TODO: Implement
return params.BloomBitsBlocks, 0 // TODO: Implement second return value
}

func (a *APIBackend) GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) {
panic("not implemented") // TODO: Implement
receipts := a.blockChain().GetReceiptsByHash(blockHash)
if receipts == nil {
return nil, nil
}
logs := make([][]*types.Log, len(receipts))
for i, receipt := range receipts {
logs[i] = receipt.Logs
}
return logs, nil
}

func (a *APIBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) {
Expand Down
7 changes: 7 additions & 0 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common

// NewEVMTxContext creates a new transaction context for a single transaction.
func NewEVMTxContext(msg Message) vm.TxContext {
originWasRemapped := false
tx := msg.UnderlyingTransaction()
if tx != nil {
txType := tx.Type()
originWasRemapped = txType == types.ArbitrumUnsignedTxType || txType == types.ArbitrumContractTxType
}
return vm.TxContext{
Origin: msg.From(),
GasPrice: new(big.Int).Set(msg.GasPrice()),
OriginWasRemapped: originWasRemapped,
}
}

Expand Down
1 change: 1 addition & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type StateTransition struct {

// Message represents a message sent to a contract.
type Message interface {
UnderlyingTransaction() *types.Transaction
From() common.Address
To() *common.Address

Expand Down
1 change: 1 addition & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type TxContext struct {
// Message information
Origin common.Address // Provides information for ORIGIN
GasPrice *big.Int // Provides information for GASPRICE
OriginWasRemapped bool // Arbitrum addition, provides information for ArbSys precopmile
}

// EVM is the Ethereum Virtual Machine base object and provides
Expand Down
22 changes: 22 additions & 0 deletions core/vm/evm_arbitrum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package vm

// Depth returns the current depth
func (evm *EVM) Depth() int {
return evm.depth
}

0 comments on commit 99434bf

Please sign in to comment.