-
Notifications
You must be signed in to change notification settings - Fork 11
base.PolymeshTransactionBatch
@polymeshassociation/polymesh-sdk / base/PolymeshTransactionBatch
Defined in: base/PolymeshTransactionBatch.ts:22
Wrapper class for a batch of Polymesh Transactions
-
PolymeshTransactionBase<ReturnValue,TransformedReturnValue>
| Type Parameter | Default type |
|---|---|
ReturnValue |
- |
TransformedReturnValue |
ReturnValue |
Args extends unknown[][] |
unknown[][] |
optionalblockHash?:string
Defined in: base/PolymeshTransactionBase.ts:107
hash of the block where this transaction resides (status: Succeeded, Failed)
PolymeshTransactionBase.blockHash
optionalblockNumber?:BigNumber
Defined in: base/PolymeshTransactionBase.ts:112
number of the block where this transaction resides (status: Succeeded, Failed)
PolymeshTransactionBase.blockNumber
optionalerror?:PolymeshError
Defined in: base/PolymeshTransactionBase.ts:87
stores errors thrown while running the transaction (status: Failed, Aborted)
multiSig:
MultiSig|null
Defined in: base/PolymeshTransactionBase.ts:120
This will be set if the signingAddress is a MultiSig signer, otherwise null
When set it indicates the transaction will be wrapped as a proposal for the MultiSig,
meaning .runAsProposal should be used instead of .run
PolymeshTransactionBase.multiSig
optionalreceipt?:ISubmittableResult
Defined in: base/PolymeshTransactionBase.ts:92
stores the transaction receipt (if successful)
PolymeshTransactionBase.receipt
status:
TransactionStatus=TransactionStatus.Idle
Defined in: base/PolymeshTransactionBase.ts:82
current status of the transaction
PolymeshTransactionBase.status
optionaltxHash?:string
Defined in: base/PolymeshTransactionBase.ts:97
transaction hash (status: Running, Succeeded, Failed)
PolymeshTransactionBase.txHash
optionaltxIndex?:BigNumber
Defined in: base/PolymeshTransactionBase.ts:102
transaction index within its block (status: Succeeded, Failed)
PolymeshTransactionBase.txIndex
get isSuccess():
boolean
Defined in: base/PolymeshTransactionBase.ts:932
returns true if transaction has completed successfully
boolean
PolymeshTransactionBase.isSuccess
get result():
TransformedReturnValue
Defined in: base/PolymeshTransactionBase.ts:843
returns the transaction result - this is the same value as the Promise run returns
it is generally preferable to await the Promise returned by transaction.run() instead of reading this property
if the transaction.isSuccess property is false — be sure to check that before accessing!
TransformedReturnValue
PolymeshTransactionBase.result
get transactions():
MapTxData<Args>
Defined in: base/PolymeshTransactionBatch.ts:78
transactions in the batch with their respective arguments
MapTxData<Args>
getTotalFees(
asProposal?):Promise<PayingAccountFees>
Defined in: base/PolymeshTransactionBase.ts:566
Retrieve a breakdown of the fees required to run this transaction, as well as the Account responsible for paying them
| Parameter | Type | Default value | Description |
|---|---|---|---|
asProposal |
boolean |
true |
When true (default), treats the transaction as a MultiSig proposal if the signing account is a MultiSig signer. When false, treats the transaction as a direct transaction from the signing account, ignoring the MultiSig. |
Promise<PayingAccountFees>
these values might be inaccurate if the transaction is run at a later time. This can be due to a governance vote or other chain related factors (like modifications to a specific subsidizer relationship or a chain upgrade)
PolymeshTransactionBase.getTotalFees
onProcessedByMiddleware(
listener):UnsubCallback
Defined in: base/PolymeshTransactionBase.ts:606
Subscribe to the results of this transaction being processed by the indexing service (and as such, available to the middleware)
| Parameter | Type | Description |
|---|---|---|
listener |
(err?) => void
|
callback function that will be called whenever the middleware is updated with the latest data. If there is an error (timeout or middleware offline) it will be passed to this callback |
unsubscribe function
this event will be fired even if the queue fails
if the middleware wasn't enabled when instantiating the SDK client
PolymeshTransactionBase.onProcessedByMiddleware
onStatusChange(
listener):UnsubCallback
Defined in: base/PolymeshTransactionBase.ts:545
Subscribe to status changes
| Parameter | Type | Description |
|---|---|---|
listener |
(transaction) => void
|
callback function that will be called whenever the status changes |
unsubscribe function
PolymeshTransactionBase.onStatusChange
run():
Promise<TransformedReturnValue>
Defined in: base/PolymeshTransactionBase.ts:285
Run the transaction, update its status and return a result if applicable. Certain transactions create Entities on the blockchain, and those Entities are returned for convenience. For example, when running a transaction that creates an Asset, the Asset itself is returned
Promise<TransformedReturnValue>
runAsProposal():
Promise<MultiSigProposal>
Defined in: base/PolymeshTransactionBase.ts:238
Run the transaction as a multiSig proposal
Promise<MultiSigProposal>
PolymeshTransactionBase.runAsProposal
splitTransactions(): (
PolymeshTransaction<void,void,unknown[]> |PolymeshTransaction<ReturnValue,TransformedReturnValue,unknown[]>)[]
Defined in: base/PolymeshTransactionBatch.ts:204
Splits this batch into its individual transactions to be run separately. This is useful if the caller is being subsidized, since batches cannot be run by subsidized Accounts
(PolymeshTransaction<void, void, unknown[]> | PolymeshTransaction<ReturnValue, TransformedReturnValue, unknown[]>)[]
the transactions returned by this method must be run in the same order they appear in the array to guarantee the same behavior. If run out of order, an error will be thrown. The result that would be obtained by running the batch is returned by running the last transaction in the array
const createAssetTx = await sdk.assets.createAsset(...);
let ticker: string;
if (isPolymeshTransactionBatch<Asset>(createAssetTx)) {
const transactions = createAssetTx.splitTransactions();
for (let i = 0; i < length; i += 1) {
const result = await transactions[i].run();
if (isAsset(result)) {
({ticker} = result)
}
}
} else {
({ ticker } = await createAssetTx.run());
}
console.log(`New Asset created! Ticker: ${ticker}`);supportsSubsidy():
boolean
Defined in: base/PolymeshTransactionBatch.ts:135
boolean
batch can only be subsidized if -
- Number of transactions in the batch are not more than 7
- Every transaction in the batch can be subsidized
PolymeshTransactionBase.supportsSubsidy
toSignablePayload(
metadata?,asProposal?):Promise<TransactionPayload>
Defined in: base/PolymeshTransactionBase.ts:868
Returns a representation intended for offline signers.
| Parameter | Type | Default value | Description |
|---|---|---|---|
metadata |
Record<string, string> |
{} |
Additional information attached to the payload, such as IDs or memos about the transaction |
asProposal |
boolean |
true |
When true (default), treats the transaction as a MultiSig proposal if the signing account is a MultiSig signer. When false, treats the transaction as a direct transaction from the signing account, ignoring the MultiSig. |
Promise<TransactionPayload>
Usually .run() should be preferred due to is simplicity.
When using this method, details like account nonces, and transaction mortality require extra consideration. Generating a payload for offline sign implies asynchronicity. If using this API, be sure each procedure is created with the correct nonce, accounting for in flight transactions, and the lifetime is sufficient.