Add support for begin..commit group transactions
This commit is contained in:
parent
9e7b26c89b
commit
c1443ebb31
|
@ -1,4 +1,3 @@
|
|||
const { encodeAddress } = require('algosdk')
|
||||
const algosdk = require('algosdk')
|
||||
const fs = require('fs')
|
||||
// eslint-disable-next-line camelcase
|
||||
|
@ -16,6 +15,7 @@ class PricecasterLib {
|
|||
this.algodClient = algodClient
|
||||
this.ownerAddr = ownerAddr
|
||||
this.minFee = 1000
|
||||
this.groupTx = []
|
||||
|
||||
/** Overrides the default VAA processor approval program filename
|
||||
* @param {string} filename New file name to use.
|
||||
|
@ -496,14 +496,56 @@ class PricecasterLib {
|
|||
if (!algosdk.isValidAddress(sender)) {
|
||||
throw new Error('Invalid sender address: ' + sender)
|
||||
}
|
||||
if (!algosdk.isValidAddress(hash)) {
|
||||
throw new Error('Invalid program hash: ' + hash)
|
||||
}
|
||||
const appArgs = []
|
||||
appArgs.push(new Uint8Array(Buffer.from('setvphash')),
|
||||
algosdk.decodeAddress(hash).publicKey)
|
||||
return await this.callApp(sender, appArgs, [], signCallback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a begin...commit section for commiting grouped transactions.
|
||||
*/
|
||||
this.beginVerifyTxGroup = async function () {
|
||||
this.groupTx = []
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} sender The sender account (typically the VAA verification stateless program)
|
||||
* @param {function} signCallback The sign callback routine.
|
||||
* @returns Transaction id.
|
||||
*/
|
||||
this.commitVerifyTxGroup = async function (sender, signCallback) {
|
||||
algosdk.assignGroupID(this.groupTx)
|
||||
|
||||
// Sign the transactions
|
||||
const signedTxns = []
|
||||
for (const tx of this.groupTx) {
|
||||
signedTxns.push(signCallback(sender, tx))
|
||||
}
|
||||
|
||||
// Submit the transaction
|
||||
const tx = await this.algodClient.sendRawTransaction(signedTxns).do()
|
||||
this.groupTx = []
|
||||
return tx.txId
|
||||
}
|
||||
|
||||
/**
|
||||
* VAA Processor: Add a verification step to a transaction group.
|
||||
* @param {*} sender The sender account (typically the VAA verification stateless program)
|
||||
* @param {*} payload The VAA payload as Uint8Array.
|
||||
* @param {*} gksubset An hex string containing the keys for the guardian subset in this step.
|
||||
* @param {*} totalguardians The total number of known guardians.
|
||||
*/
|
||||
this.addVerifyTx = async function (sender, payload, gksubset, totalguardians) {
|
||||
const appArgs = []
|
||||
appArgs.push(new Uint8Array(Buffer.from(gksubset, 'hex')), algosdk.encodeUint64(parseInt(totalguardians)))
|
||||
this.groupTx.push(algosdk.makeApplicationNoOpTxn(sender,
|
||||
appArgs,
|
||||
this.appId,
|
||||
undefined, undefined, undefined, undefined,
|
||||
payload))
|
||||
this.groupTx.push()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue