Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
6952fe3a
Commit
6952fe3a
authored
Oct 17, 2016
by
Felix Lange
Committed by
GitHub
Oct 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3100 from kobigurk/develop
internal/ethapi, internal/web3ext: adds raw tx retrieval methods
parents
b19b7c39
1a6682c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
api.go
internal/ethapi/api.go
+42
-1
web3ext.go
internal/web3ext/web3ext.go
+13
-0
No files found.
internal/ethapi/api.go
View file @
6952fe3a
...
@@ -597,7 +597,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
...
@@ -597,7 +597,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
"gasUsed"
:
rpc
.
NewHexNumber
(
head
.
GasUsed
),
"gasUsed"
:
rpc
.
NewHexNumber
(
head
.
GasUsed
),
"timestamp"
:
rpc
.
NewHexNumber
(
head
.
Time
),
"timestamp"
:
rpc
.
NewHexNumber
(
head
.
Time
),
"transactionsRoot"
:
head
.
TxHash
,
"transactionsRoot"
:
head
.
TxHash
,
"receiptsRoot"
:
head
.
ReceiptHash
,
"receiptsRoot"
:
head
.
ReceiptHash
,
}
}
if
inclTx
{
if
inclTx
{
...
@@ -699,6 +699,16 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
...
@@ -699,6 +699,16 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
return
nil
,
nil
return
nil
,
nil
}
}
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
func
newRPCRawTransactionFromBlockIndex
(
b
*
types
.
Block
,
txIndex
int
)
(
rpc
.
HexBytes
,
error
)
{
if
txIndex
>=
0
&&
txIndex
<
len
(
b
.
Transactions
())
{
tx
:=
b
.
Transactions
()[
txIndex
]
return
rlp
.
EncodeToBytes
(
tx
)
}
return
nil
,
nil
}
// newRPCTransaction returns a transaction that will serialize to the RPC representation.
// newRPCTransaction returns a transaction that will serialize to the RPC representation.
func
newRPCTransaction
(
b
*
types
.
Block
,
txHash
common
.
Hash
)
(
*
RPCTransaction
,
error
)
{
func
newRPCTransaction
(
b
*
types
.
Block
,
txHash
common
.
Hash
)
(
*
RPCTransaction
,
error
)
{
for
idx
,
tx
:=
range
b
.
Transactions
()
{
for
idx
,
tx
:=
range
b
.
Transactions
()
{
...
@@ -770,6 +780,22 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
...
@@ -770,6 +780,22 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
return
nil
,
nil
return
nil
,
nil
}
}
// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByBlockNumberAndIndex
(
ctx
context
.
Context
,
blockNr
rpc
.
BlockNumber
,
index
rpc
.
HexNumber
)
(
rpc
.
HexBytes
,
error
)
{
if
block
,
_
:=
s
.
b
.
BlockByNumber
(
ctx
,
blockNr
);
block
!=
nil
{
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
}
return
nil
,
nil
}
// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByBlockHashAndIndex
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
index
rpc
.
HexNumber
)
(
rpc
.
HexBytes
,
error
)
{
if
block
,
_
:=
s
.
b
.
GetBlock
(
ctx
,
blockHash
);
block
!=
nil
{
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
}
return
nil
,
nil
}
// GetTransactionCount returns the number of transactions the given address has sent for the given block number
// GetTransactionCount returns the number of transactions the given address has sent for the given block number
func
(
s
*
PublicTransactionPoolAPI
)
GetTransactionCount
(
ctx
context
.
Context
,
address
common
.
Address
,
blockNr
rpc
.
BlockNumber
)
(
*
rpc
.
HexNumber
,
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
GetTransactionCount
(
ctx
context
.
Context
,
address
common
.
Address
,
blockNr
rpc
.
BlockNumber
)
(
*
rpc
.
HexNumber
,
error
)
{
state
,
_
,
err
:=
s
.
b
.
StateAndHeaderByNumber
(
blockNr
)
state
,
_
,
err
:=
s
.
b
.
StateAndHeaderByNumber
(
blockNr
)
...
@@ -835,6 +861,21 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
...
@@ -835,6 +861,21 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
return
nil
,
nil
return
nil
,
nil
}
}
// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByHash
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
rpc
.
HexBytes
,
error
)
{
var
tx
*
types
.
Transaction
var
err
error
if
tx
,
_
,
err
=
getTransaction
(
s
.
b
.
ChainDb
(),
s
.
b
,
txHash
);
err
!=
nil
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v
\n
"
,
err
)
return
nil
,
nil
}
else
if
tx
==
nil
{
return
nil
,
nil
}
return
rlp
.
EncodeToBytes
(
tx
)
}
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func
(
s
*
PublicTransactionPoolAPI
)
GetTransactionReceipt
(
txHash
common
.
Hash
)
(
map
[
string
]
interface
{},
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
GetTransactionReceipt
(
txHash
common
.
Hash
)
(
map
[
string
]
interface
{},
error
)
{
receipt
:=
core
.
GetReceipt
(
s
.
b
.
ChainDb
(),
txHash
)
receipt
:=
core
.
GetReceipt
(
s
.
b
.
ChainDb
(),
txHash
)
...
...
internal/web3ext/web3ext.go
View file @
6952fe3a
...
@@ -468,6 +468,19 @@ web3._extend({
...
@@ -468,6 +468,19 @@ web3._extend({
call: 'eth_submitTransaction',
call: 'eth_submitTransaction',
params: 1,
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'getRawTransaction',
call: 'eth_getRawTransactionByHash',
params: 1
}),
new web3._extend.Method({
name: 'getRawTransactionFromBlock',
call: function(args) {
return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
},
params: 2,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
})
})
],
],
properties:
properties:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment