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

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Aug 5, 2019

This PR adds eth.fillTransaction, which is useful if signing is done outside of the actual node.

Below is a reference about what methods exist today (we might want to make it into a table and place in the docs)

Example

Example when using geth --dev, which does not really have a sensible GPO.

> eth.fillTransaction({"to":"0x17Ff1b635D4A1E4Ba1377E06d1dD0e1C9015FB5f", value:"100", from:"0x17Ff1b635D4A1E4Ba1377E06d1dD0e1C9015FB5f"})
{
  raw: "0xdf80018252089417ff1b635d4a1e4ba1377e06d1dd0e1c9015fb5f6480808080",
  tx: {
    gas: "0x5208",
    gasPrice: "0x1",
    hash: "0xea7d97f5fe68d9fc638410cf134f3785ef690330660069252e5d7bb2f122f6c7",
    input: "0x",
    nonce: "0x0",
    r: "0x0",
    s: "0x0",
    to: "0x17ff1b635d4a1e4ba1377e06d1dd0e1c9015fb5f",
    v: "0x0",
    value: "0x64"
  }
}

Transaction methods

Namespace Function Broadcasts Requires accounts Output Fills defaults
eth sendTransaction Yes Yes hash Yes
eth sendRawTransaction Yes No hash No
eth signTransaction No Yes RLP + JSON (signed tx) No
eth resend Yes Yes hash Yes
eth fillTransaction No No RLP+JSON (unsigned tx) Yes
personal sendTransaction Yes Yes hash Yes
personal signTransaction No Yes RLP+JSON (signed tx) No
  • eth.sendTransaction
    • Creates a transaction from input, sign it and broadcast
    • Sets defaults
  • eth.sendRawTransaction
    • Takes a fully complete (filled and signed) transactoin in RLP-form, and broadcasts
  • eth.signTransaction
    • Takes a fully filled (unsigned) transaction, signs and broadasts
  • eth.resend
    • Matches nonce if sending-account to an existing tx, applies modifications, signs and broadcasts
    • Requires nonce, fills other defaults
  • eth.fillTransaction
    • Fills defaults and returns RLP + JSON
  • personal.sendTransaction
    • Creates a transaction from input, fills defaults, sign it and broadcast
  • personal.signTransaction
    • Creates a fully filled transaction from input, sign it and returns RLP + JSON

@fjl fjl changed the title ethapi: implement fillTransaction internal/ethapi: implement fillTransaction Aug 6, 2019
internal/jsre/deps/web3.js Outdated Show resolved Hide resolved
@holiman
Copy link
Contributor Author

holiman commented Aug 8, 2019

Fixed, ptal

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.

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants