create/SubmitMessage in pclib.
This commit is contained in:
parent
b124740baf
commit
06f7e6ee38
|
@ -188,7 +188,7 @@ class PricecasterLib {
|
|||
params.flatFee = true
|
||||
|
||||
// create unsigned transaction
|
||||
const txApp = algosdk.makeApplicationNoOpTxn(sender, params, this.appId, appArgs, appAccounts)
|
||||
const txApp = algosdk.makeApplicationNoOpTxn(sender, params, this.appId, appArgs, appAccounts.length === 0 ? undefined : appAccounts)
|
||||
const txId = txApp.txID().toString()
|
||||
|
||||
// Sign the transaction
|
||||
|
@ -296,6 +296,44 @@ class PricecasterLib {
|
|||
// display results
|
||||
return this.algodClient.pendingTransactionInformation(txId).do()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a message with price data for the PriceKeeper contract
|
||||
* @param {BigInt} nonce Sequence number
|
||||
* @param {String} symbol Symbol, must match appid support, 16-char UTF long
|
||||
* @param {number} price Price, expected in 64-bit floating-point format.
|
||||
* @param {number} confidence Confidence, expected in 64-bit floating-point format.
|
||||
* @param {Uint8Array} sk Signing key.
|
||||
* @returns A base64-encoded message.
|
||||
*/
|
||||
this.createMessage = function (nonce, symbol, price, confidence, sk) {
|
||||
const buf = Buffer.alloc(131)
|
||||
buf.write('PRICEDATA', 0)
|
||||
buf.writeInt8(1, 9)
|
||||
buf.writeBigUInt64BE(BigInt(this.appId), 10)
|
||||
buf.writeBigUInt64BE(nonce, 18)
|
||||
buf.write(symbol, 26)
|
||||
buf.writeDoubleBE(price, 42)
|
||||
buf.writeDoubleBE(confidence, 50)
|
||||
buf.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)), 58)
|
||||
|
||||
const signature = Buffer.from(algosdk.signBytes(buf, sk))
|
||||
signature.copy(buf, 66)
|
||||
|
||||
// v-component (ignored in Algorand it seems)
|
||||
buf.writeInt8(1, 130)
|
||||
return buf.toString('base64')
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits message to the PriceKeeper contract.
|
||||
* @param {*} sender Sender account
|
||||
* @param {*} msgb64 Base64-encoded message.
|
||||
* @returns Transaction identifier (txid)
|
||||
*/
|
||||
this.submitMessage = async function (sender, msgb64, signCallback) {
|
||||
return await this.callApp(sender, [new Uint8Array(msgb64)], [], signCallback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue