fix: enable serialization of unsigned transactions
This commit is contained in:
committed by
Michael Vines
parent
6d5b655413
commit
fddf2e54e9
@@ -16,6 +16,13 @@ import type {Blockhash} from './blockhash';
|
||||
*/
|
||||
export type TransactionSignature = string;
|
||||
|
||||
/**
|
||||
* Default (empty) signature
|
||||
*
|
||||
* Signatures are 64 bytes in length
|
||||
*/
|
||||
const DEFAULT_SIGNATURE = Array(64).fill(0);
|
||||
|
||||
/**
|
||||
* Maximum over-the-wire size of a Transaction
|
||||
*
|
||||
@@ -164,7 +171,6 @@ export class Transaction {
|
||||
}
|
||||
|
||||
const keys = this.signatures.map(({publicKey}) => publicKey.toString());
|
||||
let numRequiredSignatures = 0;
|
||||
let numCreditOnlySignedAccounts = 0;
|
||||
let numCreditOnlyUnsignedAccounts = 0;
|
||||
|
||||
@@ -175,7 +181,10 @@ export class Transaction {
|
||||
const keyStr = keySignerPair.pubkey.toString();
|
||||
if (!keys.includes(keyStr)) {
|
||||
if (keySignerPair.isSigner) {
|
||||
numRequiredSignatures += 1;
|
||||
this.signatures.push({
|
||||
signature: null,
|
||||
publicKey: keySignerPair.pubkey,
|
||||
});
|
||||
if (!keySignerPair.isDebitable) {
|
||||
numCreditOnlySignedAccounts += 1;
|
||||
}
|
||||
@@ -201,12 +210,6 @@ export class Transaction {
|
||||
}
|
||||
});
|
||||
|
||||
if (numRequiredSignatures > this.signatures.length) {
|
||||
throw new Error(
|
||||
`Insufficent signatures: expected ${numRequiredSignatures} but got ${this.signatures.length}`,
|
||||
);
|
||||
}
|
||||
|
||||
let keyCount = [];
|
||||
shortvec.encodeLength(keyCount, keys.length);
|
||||
|
||||
@@ -391,12 +394,13 @@ export class Transaction {
|
||||
invariant(signatures.length < 256);
|
||||
Buffer.from(signatureCount).copy(wireTransaction, 0);
|
||||
signatures.forEach(({signature}, index) => {
|
||||
invariant(signature !== null, `null signature`);
|
||||
invariant(signature.length === 64, `signature has invalid length`);
|
||||
Buffer.from(signature).copy(
|
||||
wireTransaction,
|
||||
signatureCount.length + index * 64,
|
||||
);
|
||||
if (signature !== null) {
|
||||
invariant(signature.length === 64, `signature has invalid length`);
|
||||
Buffer.from(signature).copy(
|
||||
wireTransaction,
|
||||
signatureCount.length + index * 64,
|
||||
);
|
||||
}
|
||||
});
|
||||
signData.copy(
|
||||
wireTransaction,
|
||||
@@ -506,7 +510,10 @@ export class Transaction {
|
||||
transaction.recentBlockhash = new PublicKey(recentBlockhash).toBase58();
|
||||
for (let i = 0; i < signatureCount; i++) {
|
||||
const sigPubkeyPair = {
|
||||
signature: Buffer.from(signatures[i]),
|
||||
signature:
|
||||
signatures[i].toString() == DEFAULT_SIGNATURE.toString()
|
||||
? null
|
||||
: Buffer.from(signatures[i]),
|
||||
publicKey: new PublicKey(accounts[i]),
|
||||
};
|
||||
transaction.signatures.push(sigPubkeyPair);
|
||||
|
Reference in New Issue
Block a user