mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
Finish receipts, add logs
This commit is contained in:
parent
e0f4d7e9e5
commit
c46a697c26
1 changed files with 73 additions and 18 deletions
|
|
@ -153,6 +153,36 @@ func (a *Account) Storage(ctx context.Context, args StorageSlotArgs) (HexBytes,
|
||||||
return HexBytes{state.GetState(a.address, common.BytesToHash(args.Slot.Bytes)).Bytes()}, nil
|
return HexBytes{state.GetState(a.address, common.BytesToHash(args.Slot.Bytes)).Bytes()}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Log struct {
|
||||||
|
node *node.Node
|
||||||
|
transaction *Transaction
|
||||||
|
log *types.Log
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Log) Transaction(ctx context.Context) *Transaction {
|
||||||
|
return l.transaction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Log) Account(ctx context.Context, args BlockNumberArgs) *Account {
|
||||||
|
return &Account{
|
||||||
|
node: l.node,
|
||||||
|
address: l.log.Address,
|
||||||
|
blockNumber: args.Number(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Log) Topics(ctx context.Context) []*HexBytes {
|
||||||
|
ret := make([]*HexBytes, 0, len(l.log.Topics))
|
||||||
|
for _, topic := range l.log.Topics {
|
||||||
|
ret = append(ret, &HexBytes{topic.Bytes()})
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Log) Data(ctx context.Context) HexBytes {
|
||||||
|
return HexBytes{l.log.Data}
|
||||||
|
}
|
||||||
|
|
||||||
type Receipt struct {
|
type Receipt struct {
|
||||||
node *node.Node
|
node *node.Node
|
||||||
transaction *Transaction
|
transaction *Transaction
|
||||||
|
|
@ -171,6 +201,30 @@ func (r *Receipt) CumulativeGasUsed(ctx context.Context) int32 {
|
||||||
return int32(r.receipt.CumulativeGasUsed)
|
return int32(r.receipt.CumulativeGasUsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Receipt) Contract(ctx context.Context, args BlockNumberArgs) *Account {
|
||||||
|
if r.receipt.ContractAddress == (common.Address{}) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Account{
|
||||||
|
node: r.node,
|
||||||
|
address: r.receipt.ContractAddress,
|
||||||
|
blockNumber: args.Number(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Receipt) Logs(ctx context.Context) []*Log {
|
||||||
|
ret := make([]*Log, 0, len(r.receipt.Logs))
|
||||||
|
for _, log := range r.receipt.Logs {
|
||||||
|
ret = append(ret, &Log{
|
||||||
|
node: r.node,
|
||||||
|
transaction: r.transaction,
|
||||||
|
log: log,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
type Transaction struct {
|
type Transaction struct {
|
||||||
node *node.Node
|
node *node.Node
|
||||||
hash common.Hash
|
hash common.Hash
|
||||||
|
|
@ -256,15 +310,10 @@ func (t *Transaction) To(ctx context.Context, args BlockNumberArgs) (*Account, e
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
block := rpc.LatestBlockNumber
|
|
||||||
if args.Block != nil {
|
|
||||||
block = rpc.BlockNumber(*args.Block)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Account{
|
return &Account{
|
||||||
node: t.node,
|
node: t.node,
|
||||||
address: *to,
|
address: *to,
|
||||||
blockNumber: block,
|
blockNumber: args.Number(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,11 +323,6 @@ func (t *Transaction) From(ctx context.Context, args BlockNumberArgs) (*Account,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
block := rpc.LatestBlockNumber
|
|
||||||
if args.Block != nil {
|
|
||||||
block = rpc.BlockNumber(*args.Block)
|
|
||||||
}
|
|
||||||
|
|
||||||
var signer types.Signer = types.FrontierSigner{}
|
var signer types.Signer = types.FrontierSigner{}
|
||||||
if tx.Protected() {
|
if tx.Protected() {
|
||||||
signer = types.NewEIP155Signer(tx.ChainId())
|
signer = types.NewEIP155Signer(tx.ChainId())
|
||||||
|
|
@ -288,7 +332,7 @@ func (t *Transaction) From(ctx context.Context, args BlockNumberArgs) (*Account,
|
||||||
return &Account{
|
return &Account{
|
||||||
node: t.node,
|
node: t.node,
|
||||||
address: from,
|
address: from,
|
||||||
blockNumber: block,
|
blockNumber: args.Number(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -542,21 +586,23 @@ type BlockNumberArgs struct {
|
||||||
Block *int32
|
Block *int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a BlockNumberArgs) Number() rpc.BlockNumber {
|
||||||
|
if a.Block != nil {
|
||||||
|
return rpc.BlockNumber(*a.Block)
|
||||||
|
}
|
||||||
|
return rpc.LatestBlockNumber
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Block) Coinbase(ctx context.Context, args BlockNumberArgs) (*Account, error) {
|
func (b *Block) Coinbase(ctx context.Context, args BlockNumberArgs) (*Account, error) {
|
||||||
block, err := b.resolve(ctx)
|
block, err := b.resolve(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blockNumber := rpc.LatestBlockNumber
|
|
||||||
if args.Block != nil {
|
|
||||||
blockNumber = rpc.BlockNumber(*args.Block)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Account{
|
return &Account{
|
||||||
node: b.node,
|
node: b.node,
|
||||||
address: block.Coinbase(),
|
address: block.Coinbase(),
|
||||||
blockNumber: blockNumber,
|
blockNumber: args.Number(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -676,10 +722,19 @@ func NewHandler(n *node.Node) (http.Handler, error) {
|
||||||
storage(slot: HexBytes!): HexBytes!
|
storage(slot: HexBytes!): HexBytes!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Log {
|
||||||
|
transaction: Transaction!
|
||||||
|
account(block: Int): Account!
|
||||||
|
topics: [HexBytes]!
|
||||||
|
data: HexBytes!
|
||||||
|
}
|
||||||
|
|
||||||
type Receipt {
|
type Receipt {
|
||||||
status: Int!
|
status: Int!
|
||||||
gasUsed: Int!
|
gasUsed: Int!
|
||||||
cumulativeGasUsed: Int!
|
cumulativeGasUsed: Int!
|
||||||
|
contract(block: Int): Account
|
||||||
|
logs: [Log]!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transaction {
|
type Transaction {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue