Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: implement fillTransaction #19915

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,22 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
return SubmitTransaction(ctx, s.b, signed)
}

// FillTransaction fills the defaults (nonce, gas, gasPrice) on a given unsigned transaction,
// and returns it to the caller for further processing (signing + broadcast)
func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
// Set some sanity defaults and terminate on failure
if err := args.setDefaults(ctx, s.b); err != nil {
return nil, err
}
// Assemble the transaction and obtain rlp
tx := args.toTransaction()
data, err := rlp.EncodeToBytes(tx)
if err != nil {
return nil, err
}
return &SignTransactionResult{data, tx}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, shouldn't we perhaps declare a type FillTransactionResult that does not return R, S, V?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe... I'm not sure it solves the usability question. So here are the steps you need to go through to actually fill and sign a tx:

> a = eth.fillTransaction({"to":"0x17Ff1b635D4A1E4Ba1377E06d1dD0e1C9015FB5f", value:"100", from:eth.accounts[0]})
{
  raw: "0xdf80018252089417ff1b635d4a1e4ba1377e06d1dd0e1c9015fb5f6480808080",
  tx: {
    gas: "0x5208",
    gasPrice: "0x1",
    hash: "0xea7d97f5fe68d9fc638410cf134f3785ef690330660069252e5d7bb2f122f6c7",
    input: "0x",
    nonce: "0x0",
    r: "0x0",
    s: "0x0",
    to: "0x17ff1b635d4a1e4ba1377e06d1dd0e1c9015fb5f",
    v: "0x0",
    value: "0x64"
  }
}
> a.tx.from = eth.accounts[0]
"0x42e44603164ac2384c2c0894fe67b344a9f1f50b"
> eth.signTransaction(a.tx)
{
  raw: "0xf86180018252089417ff1b635d4a1e4ba1377e06d1dd0e1c9015fb5f6480820a95a013c4a9a47cd447a6bef6a085b20e02ae393205bac903e74535c103c33bc54021a02d0ef0739ebd9267197625c0fb154619b0e385066e362dbac55fbdf57e68773a",
  tx: {
    gas: "0x5208",
    gasPrice: "0x1",
    hash: "0x656acc325802797f991d98ba48f8bd383332bcdbc4c390ac790740139c1adfe9",
    input: "0x",
    nonce: "0x0",
    r: "0x13c4a9a47cd447a6bef6a085b20e02ae393205bac903e74535c103c33bc54021",
    s: "0x2d0ef0739ebd9267197625c0fb154619b0e385066e362dbac55fbdf57e68773a",
    to: "0x17ff1b635d4a1e4ba1377e06d1dd0e1c9015fb5f",
    v: "0xa95",
    value: "0x64"
  }
}

You need to explicitly set the from. Would be neat if we could pass the output from fill as input to sign.

}

// SendRawTransaction will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
Expand Down
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ web3._extend({
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'fillTransaction',
call: 'eth_fillTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'getHeaderByNumber',
call: 'eth_getHeaderByNumber',
Expand Down