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
6bb29aeb
Commit
6bb29aeb
authored
Nov 20, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1666 from obscuren/create-transaction
rpc/api, xeth: added signTransaction method
parents
314c031f
6ea05f5a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
7 deletions
+115
-7
eth.go
rpc/api/eth.go
+44
-2
eth_js.go
rpc/api/eth_js.go
+17
-5
xeth.go
xeth/xeth.go
+54
-0
No files found.
rpc/api/eth.go
View file @
6bb29aeb
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/natspec"
"github.com/ethereum/go-ethereum/common/natspec"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
...
@@ -70,8 +71,10 @@ var (
...
@@ -70,8 +71,10 @@ var (
"eth_getCode"
:
(
*
ethApi
)
.
GetData
,
"eth_getCode"
:
(
*
ethApi
)
.
GetData
,
"eth_getNatSpec"
:
(
*
ethApi
)
.
GetNatSpec
,
"eth_getNatSpec"
:
(
*
ethApi
)
.
GetNatSpec
,
"eth_sign"
:
(
*
ethApi
)
.
Sign
,
"eth_sign"
:
(
*
ethApi
)
.
Sign
,
"eth_sendRawTransaction"
:
(
*
ethApi
)
.
SendRawTransaction
,
"eth_sendRawTransaction"
:
(
*
ethApi
)
.
SubmitTransaction
,
"eth_submitTransaction"
:
(
*
ethApi
)
.
SubmitTransaction
,
"eth_sendTransaction"
:
(
*
ethApi
)
.
SendTransaction
,
"eth_sendTransaction"
:
(
*
ethApi
)
.
SendTransaction
,
"eth_signTransaction"
:
(
*
ethApi
)
.
SignTransaction
,
"eth_transact"
:
(
*
ethApi
)
.
SendTransaction
,
"eth_transact"
:
(
*
ethApi
)
.
SendTransaction
,
"eth_estimateGas"
:
(
*
ethApi
)
.
EstimateGas
,
"eth_estimateGas"
:
(
*
ethApi
)
.
EstimateGas
,
"eth_call"
:
(
*
ethApi
)
.
Call
,
"eth_call"
:
(
*
ethApi
)
.
Call
,
...
@@ -285,7 +288,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) {
...
@@ -285,7 +288,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) {
return
v
,
nil
return
v
,
nil
}
}
func
(
self
*
ethApi
)
S
endRaw
Transaction
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
func
(
self
*
ethApi
)
S
ubmit
Transaction
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
NewDataArgs
)
args
:=
new
(
NewDataArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
...
@@ -298,6 +301,45 @@ func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error)
...
@@ -298,6 +301,45 @@ func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error)
return
v
,
nil
return
v
,
nil
}
}
// JsonTransaction is returned as response by the JSON RPC. It contains the
// signed RLP encoded transaction as Raw and the signed transaction object as Tx.
type
JsonTransaction
struct
{
Raw
string
`json:"raw"`
Tx
*
tx
`json:"tx"`
}
func
(
self
*
ethApi
)
SignTransaction
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
NewTxArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
// nonce may be nil ("guess" mode)
var
nonce
string
if
args
.
Nonce
!=
nil
{
nonce
=
args
.
Nonce
.
String
()
}
var
gas
,
price
string
if
args
.
Gas
!=
nil
{
gas
=
args
.
Gas
.
String
()
}
if
args
.
GasPrice
!=
nil
{
price
=
args
.
GasPrice
.
String
()
}
tx
,
err
:=
self
.
xeth
.
SignTransaction
(
args
.
From
,
args
.
To
,
nonce
,
args
.
Value
.
String
(),
gas
,
price
,
args
.
Data
)
if
err
!=
nil
{
return
nil
,
err
}
data
,
err
:=
rlp
.
EncodeToBytes
(
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
JsonTransaction
{
"0x"
+
common
.
Bytes2Hex
(
data
),
newTx
(
tx
)},
nil
}
func
(
self
*
ethApi
)
SendTransaction
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
func
(
self
*
ethApi
)
SendTransaction
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
NewTxArgs
)
args
:=
new
(
NewTxArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
rpc/api/eth_js.go
View file @
6bb29aeb
...
@@ -36,11 +36,23 @@ web3._extend({
...
@@ -36,11 +36,23 @@ web3._extend({
params: 3,
params: 3,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
}),
}),
new web3._extend.Method({
new web3._extend.Method({
name: 'getNatSpec',
name: 'getNatSpec',
call: 'eth_getNatSpec',
call: 'eth_getNatSpec',
params: 1,
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'signTransaction',
call: 'eth_signTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'submitTransaction',
call: 'eth_submitTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
})
})
],
],
properties:
properties:
...
...
xeth/xeth.go
View file @
6bb29aeb
...
@@ -879,6 +879,60 @@ func (self *XEth) Frontend() Frontend {
...
@@ -879,6 +879,60 @@ func (self *XEth) Frontend() Frontend {
return
self
.
frontend
return
self
.
frontend
}
}
func
(
self
*
XEth
)
SignTransaction
(
fromStr
,
toStr
,
nonceStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
*
types
.
Transaction
,
error
)
{
if
len
(
toStr
)
>
0
&&
toStr
!=
"0x"
&&
!
isAddress
(
toStr
)
{
return
nil
,
errors
.
New
(
"Invalid address"
)
}
var
(
from
=
common
.
HexToAddress
(
fromStr
)
to
=
common
.
HexToAddress
(
toStr
)
value
=
common
.
Big
(
valueStr
)
gas
*
big
.
Int
price
*
big
.
Int
data
[]
byte
contractCreation
bool
)
if
len
(
gasStr
)
==
0
{
gas
=
DefaultGas
()
}
else
{
gas
=
common
.
Big
(
gasStr
)
}
if
len
(
gasPriceStr
)
==
0
{
price
=
self
.
DefaultGasPrice
()
}
else
{
price
=
common
.
Big
(
gasPriceStr
)
}
data
=
common
.
FromHex
(
codeStr
)
if
len
(
toStr
)
==
0
{
contractCreation
=
true
}
var
nonce
uint64
if
len
(
nonceStr
)
!=
0
{
nonce
=
common
.
Big
(
nonceStr
)
.
Uint64
()
}
else
{
state
:=
self
.
backend
.
TxPool
()
.
State
()
nonce
=
state
.
GetNonce
(
from
)
}
var
tx
*
types
.
Transaction
if
contractCreation
{
tx
=
types
.
NewContractCreation
(
nonce
,
value
,
gas
,
price
,
data
)
}
else
{
tx
=
types
.
NewTransaction
(
nonce
,
to
,
value
,
gas
,
price
,
data
)
}
signed
,
err
:=
self
.
sign
(
tx
,
from
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
return
signed
,
nil
}
func
(
self
*
XEth
)
Transact
(
fromStr
,
toStr
,
nonceStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
Transact
(
fromStr
,
toStr
,
nonceStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
// this minimalistic recoding is enough (works for natspec.js)
// this minimalistic recoding is enough (works for natspec.js)
...
...
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