fix: remove unwanted u64 length from raw Transaction bytes, it's RPC API specific
This commit is contained in:
parent
5bb07e541d
commit
564d09fdfe
|
@ -431,8 +431,15 @@ export class Connection {
|
|||
async sendRawTransaction(
|
||||
rawTransaction: Buffer,
|
||||
): Promise<TransactionSignature> {
|
||||
|
||||
// sendTransaction RPC API requires a u64 length field prepended to the raw
|
||||
// Transaction bytes
|
||||
const rpcTransaction = Buffer.alloc(8 + rawTransaction.length);
|
||||
rpcTransaction.writeUInt32LE(rawTransaction.length, 0);
|
||||
rawTransaction.copy(rpcTransaction, 8);
|
||||
|
||||
const unsafeRes = await this._rpcRequest('sendTransaction', [
|
||||
[...rawTransaction],
|
||||
[...rpcTransaction],
|
||||
]);
|
||||
const res = SendTransactionRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
|
|
|
@ -365,21 +365,20 @@ export class Transaction {
|
|||
shortvec.encodeLength(signatureCount, signatures.length);
|
||||
const transactionLength =
|
||||
signatureCount.length + signatures.length * 64 + signData.length;
|
||||
const wireTransaction = Buffer.alloc(8 + transactionLength);
|
||||
wireTransaction.writeUInt32LE(transactionLength, 0);
|
||||
const wireTransaction = Buffer.alloc(transactionLength);
|
||||
invariant(signatures.length < 256);
|
||||
Buffer.from(signatureCount).copy(wireTransaction, 8);
|
||||
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,
|
||||
8 + signatureCount.length + index * 64,
|
||||
signatureCount.length + index * 64,
|
||||
);
|
||||
});
|
||||
signData.copy(
|
||||
wireTransaction,
|
||||
8 + signatureCount.length + signatures.length * 64,
|
||||
signatureCount.length + signatures.length * 64,
|
||||
);
|
||||
invariant(
|
||||
wireTransaction.length <= PACKET_DATA_SIZE,
|
||||
|
@ -427,11 +426,6 @@ export class Transaction {
|
|||
// Slice up wire data
|
||||
let byteArray = [...buffer];
|
||||
|
||||
const transactionLength = byteArray.slice(0, 8);
|
||||
byteArray = byteArray.slice(8);
|
||||
const len = Buffer.from(transactionLength).readIntLE(0, 4);
|
||||
invariant(len == byteArray.length);
|
||||
|
||||
const signatureCount = shortvec.decodeLength(byteArray);
|
||||
let signatures = [];
|
||||
for (let i = 0; i < signatureCount; i++) {
|
||||
|
|
|
@ -51,14 +51,6 @@ test('parse wire format and serialize', () => {
|
|||
expectedTransaction.sign(sender);
|
||||
|
||||
const wireTransaction = Buffer.from([
|
||||
221,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
50,
|
||||
238,
|
||||
|
|
Loading…
Reference in New Issue