stacks-archive / stacks-transactions-js

The JavaScript library for generating Stacks 2.0 transactions
19 stars 17 forks source link

tx.broadcast should return a result/error type #54

Closed kantai closed 4 years ago

kantai commented 4 years ago

It looks like tx.broadcast always succeeds:

https://github.com/blockstack/stacks-transactions-js/blob/master/src/transaction.ts#L158

Which leads to consumers like cli-blockstack to display TXIDs, when there was an error returned by the mempool, e.g.:

From branch feature/stacks-2.0-tx on cli-blockstack:

$ ./cmd/index.js send_tokens ST1WZ69T99RHQMQX3D91ZH2R37GV5NK8KDS5D5VDZ 1000 1 0 994d526b3b3409def4d3e481f9c4b3debaf9535cffed0769a7543601e1efa3c501 -t -d -T "http://127.0.0.1:20443/v2/transactions"
691a2735e0da3682a0383a7e64acea01cad02511ee25be2b57114918294b9e1a

$ ./cmd/index.js send_tokens ST1WZ69T99RHQMQX3D91ZH2R37GV5NK8KDS5D5VDZ 1000 1 0 994d526b3b3409def4d3e481f9c4b3debaf9535cffed0769a7543601e1efa3c501 -t -d -x -T "http://127.0.0.1:20443/v2/transactions" | xxd -r -p - | curl -X POST -H 'Content-Type: application/octet-stream' --data-binary "@-" 127.0.0.1:20443/v2/transactions | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   315    0   135  100   180    589    786 --:--:-- --:--:-- --:--:--  1375
{
  "txid": "691a2735e0da3682a0383a7e64acea01cad02511ee25be2b57114918294b9e1a",
  "error": "transaction rejected",
  "reason": "FeeTooLow(1, 180)"
}
zone117x commented 4 years ago

The core-node now returns structured errors, see https://github.com/blockstack/stacks-blockchain/pull/1510/files#diff-98a3f84802c72cc9abbd3ecc208654e0R23

This lib should now be updated with improved broadcast results, see https://github.com/blockstack/stacks-transactions-js/pull/43#discussion_r409627824

aulneau commented 4 years ago

Additionally this documentation was updated today: https://github.com/blockstack/stacks-blockchain/blob/feat/more-detail-tx-endpoint/docs/rpc-endpoints.md