fix: add Nonce transaction construction option

This commit is contained in:
Tyera Eulberg
2020-01-06 18:12:04 -07:00
committed by Michael Vines
parent 600a295b11
commit bd0a9348f4
2 changed files with 73 additions and 0 deletions

View File

@@ -96,9 +96,22 @@ type SignaturePubkeyPair = {|
*/
type TransactionCtorFields = {|
recentBlockhash?: Blockhash | null,
nonceInfo?: NonceInformation | null,
signatures?: Array<SignaturePubkeyPair>,
|};
/**
* NonceInformation to be used to build a Transaction.
*
* @typedef {Object} NonceInformation
* @property {nonce} The current Nonce blockhash
* @property {nonceInstruction} The NonceAdvance Instruction
*/
type NonceInformation = {|
nonce: Blockhash,
nonceInstruction: TransactionInstruction,
|};
/**
* Transaction class
*/
@@ -129,6 +142,12 @@ export class Transaction {
*/
recentBlockhash: Blockhash | null;
/**
* Optional Nonce information. If populated, transaction will use a durable
* Nonce hash instead of a recentBlockhash. Must be populated by the caller
*/
nonceInfo: NonceInformation | null;
/**
* Construct an empty Transaction
*/
@@ -164,6 +183,11 @@ export class Transaction {
* @private
*/
_getSignData(): Buffer {
const {nonceInfo} = this;
if (nonceInfo) {
this.recentBlockhash = nonceInfo.nonce;
this.instructions.unshift(nonceInfo.nonceInstruction);
}
const {recentBlockhash} = this;
if (!recentBlockhash) {
throw new Error('Transaction recentBlockhash required');