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