-
Notifications
You must be signed in to change notification settings - Fork 463
Support for Read Only Transactions #963
Changes from 8 commits
d4c35c2
f084bd4
b6966c2
6df4a34
5b1bd49
3d35686
e29147a
093c437
ac605ca
dd851d9
5597821
91fd1f7
11e3efe
c498592
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,8 @@ By providing that function inside `tx.associateContextFree()`, the transaction o | |
|
||
#### Return Values | ||
From nodeos version 2.1, the ability to receive return values from smart contracts to eosjs has been introduced. In the above examples, the `transaction` object will include the values `transaction_id` and the `processed` object. If your smart contract returns values, you will be able to find the values within the `transaction.processed.action_traces` array. The order of the `action_traces` array matches the order of actions in your transaction and within those `action_trace` objects, you can find your deserialized return value for your action in the `return_value` field. | ||
|
||
### Read-Only Transactions | ||
Adding `readOnlyTrx` to the `transact` config will send the transaction through the `push_ro_transaction` endpoint in the `chain_api`. This endpoint will ensure that the transaction will not make any changes despite the actions in the transaction. It is typically useful for doing queries using actions but normal actions will also work with this endpoint, but they won't make changes. | ||
|
||
Adding `returnFailureTraces` to the `transact` config will return a trace of the failure if your transaction fails. At this time, this is only available for read-only transactions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe: Adding to => Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed your changes slightly to state that it is only available for the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
When a call to the chain_api is performed and fails, it will result in an RPCError object being generated to inform why the transaction failed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe: When a call to the chain_api is performed and fails, it will result in an RPCError object being generated to inform why the transaction failed. to => When a call to the chain_api is performed and fails, it will result in an RPCError object being generated which contains information on why the transaction failed. |
||
|
||
The RPCError object will error with the concise message, for instance 'Invalid transaction', but additional details can be found in both the `details` field and the `json` field. The `json` field holds the entire json response from `nodeos` while the `details` field specifically holds the error object in the `json`. This is typically in different places of the `json` depending on what endpoint is used in `nodeos` so the `details` field is available to quickly see the error information without needing to search through the `json` object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe The RPCError object will error with the concise message, for instance 'Invalid transaction', but additional details can be found in both the to => The RPCError object will contain a concise error message, for instance 'Invalid transaction'. However additional details can be found in the |
||
|
||
As you can see below, the concise error message might not give enough information to really discern the issue. While the error has `eosio_assert_message assertion failure` as the concise error, in the `details` field the `overdrawn balance` error mentioned. It's important to note that the format of the `details` object can be different depending on what endpoint is used. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe As you can see below, the concise error message might not give enough information to really discern the issue. While the error has to => In the It's important to note that the format of the => as an additional thing - I think you choose the endpoint with the readOnlyTrx flag, is it worth mentioning the other endpoint explicitly and/or showing an example from calls to both endpoints -assuming there are two endpoints. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a large amount of different responses from nodeos, unfortunately it won't be easy to state all of them. |
||
```javascript | ||
RpcError: eosio_assert_message assertion failure | ||
at new RpcError (eosjs-rpcerror.ts:20:13) | ||
at JsonRpc.<anonymous> (eosjs-jsonrpc.ts:90:23) | ||
at step (eosjs-jsonrpc.js:37:23) | ||
at Object.next (eosjs-jsonrpc.js:18:53) | ||
at fulfilled (eosjs-jsonrpc.js:9:58) | ||
at processTicksAndRejections (node:internal/process/task_queues:94:5) { | ||
details: { | ||
code: 3050003, | ||
name: 'eosio_assert_message_exception', | ||
message: 'eosio_assert_message assertion failure', | ||
stack: [ | ||
{ | ||
context: { | ||
level: 'error', | ||
file: 'cf_system.cpp', | ||
line: 14, | ||
method: 'eosio_assert', | ||
hostname: '', | ||
thread_name: 'nodeos', | ||
timestamp: '2021-06-16T05:26:03.665' | ||
}, | ||
format: 'assertion failure with message: ${s}', | ||
data: { s: 'overdrawn balance' } | ||
}, | ||
{ | ||
context: { | ||
level: 'warn', | ||
file: 'apply_context.cpp', | ||
line: 143, | ||
method: 'exec_one', | ||
hostname: '', | ||
thread_name: 'nodeos', | ||
timestamp: '2021-06-16T05:26:03.665' | ||
}, | ||
format: 'pending console output: ${console}', | ||
data: { console: '' } | ||
} | ||
] | ||
}, | ||
json: { | ||
head_block_num: 1079, | ||
head_block_id: '00003384ff2dd671472e8290e7ee0fbc00ee1f450ce5c10de0a9c245ab5b5b22', | ||
last_irreversible_block_num: 1070, | ||
last_irreversible_block_id: '00003383946519b67bac1a0f31898826b472d81fd40b7fccb49a2f486bd292d1', | ||
code_hash: '800bb7fedd86155047064bffdaa3c32cca76cda40eb80f5c4a7676c7f57da579', | ||
pending_transactions: [], | ||
result: { | ||
id: '01a0cbb6c0215df53f07ecdcf0fb750a4134938b38a72946a0f6f25cf3f43bcb', | ||
block_num: 1079, | ||
block_time: '2021-06-14T21:13:04.500', | ||
producer_block_id: null, | ||
receipt: null, | ||
elapsed: 189, | ||
net_usage: 137, | ||
scheduled: false, | ||
action_traces: [Array], | ||
account_ram_delta: null, | ||
except: [Object], | ||
error_code: '10000000000000000000', | ||
bill_to_accounts: [] | ||
} | ||
}, | ||
isFetchError: true | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import { | |
GetTableRowsResult, | ||
PushTransactionArgs, | ||
PackedTrx, | ||
ReadOnlyTransactResult, | ||
GetBlockHeaderStateResult, | ||
GetTableByScopeResult, | ||
DBSizeGetResult, | ||
|
@@ -85,6 +86,8 @@ export class JsonRpc implements AuthorityProvider, AbiProvider { | |
json = await response.json(); | ||
if (json.processed && json.processed.except) { | ||
throw new RpcError(json); | ||
} else if (json.result && json.result.except) { | ||
throw new RpcError(json); | ||
} | ||
} catch (e) { | ||
e.isFetchError = true; | ||
|
@@ -93,6 +96,7 @@ export class JsonRpc implements AuthorityProvider, AbiProvider { | |
if (!response.ok) { | ||
throw new RpcError(json); | ||
} | ||
// check each return value for every action for an error and call `new RpcError`? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this comment |
||
return json; | ||
} | ||
|
||
|
@@ -311,6 +315,20 @@ export class JsonRpc implements AuthorityProvider, AbiProvider { | |
}); | ||
} | ||
|
||
/** Raw call to `/v1/chain/push_ro_transaction */ | ||
public async push_ro_transaction({ signatures, compression = 0, serializedTransaction }: PushTransactionArgs, | ||
returnFailureTraces: boolean = false): Promise<ReadOnlyTransactResult> { | ||
return await this.fetch('/v1/chain/push_ro_transaction', { | ||
transaction: { | ||
signatures, | ||
compression, | ||
packed_context_free_data: arrayToHex(new Uint8Array(0)), | ||
packed_trx: arrayToHex(serializedTransaction), | ||
}, | ||
return_failure_traces: returnFailureTraces, | ||
}); | ||
} | ||
|
||
public async push_transactions(transactions: PushTransactionArgs[]): Promise<TransactResult[]> { | ||
const packedTrxs: PackedTrx[] = transactions.map(({signatures, compression = 0, serializedTransaction, serializedContextFreeData }: PushTransactionArgs) => { | ||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
This endpoint will ensure that the transaction will not make any changes despite the actions in the transaction. It is typically useful for doing queries using actions but normal actions will also work with this endpoint, but they won't make changes.
to ->
The
push_ro_transaction
endpoint does not allow the transaction to make any data changes despite the actions in the transaction. Thepush_ro_transaction
endpoint may also be used to call normal actions, though the actions will not make any data changes. => what if you call an action that does make changes - is this rolled back? Perhaps explicitly state what happens in this case <=There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From nodeos version 2.2, read-only queries have been introduced to eosjs. Adding
readOnlyTrx
to thetransact
config ... etcThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is rolled back, so I changed your adjustments slightly to state that.