fix: update getConfirmedBlock json-rpc formatting
This commit is contained in:
committed by
Michael Vines
parent
3265f3bfa0
commit
fc007b02ae
@ -437,15 +437,15 @@ const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult('number');
|
|||||||
*/
|
*/
|
||||||
export const GetConfirmedBlockRpcResult = jsonRpcResult(
|
export const GetConfirmedBlockRpcResult = jsonRpcResult(
|
||||||
struct({
|
struct({
|
||||||
blockhash: struct.list(['number']),
|
blockhash: 'string',
|
||||||
previousBlockhash: struct.list(['number']),
|
previousBlockhash: 'string',
|
||||||
parentSlot: 'number',
|
parentSlot: 'number',
|
||||||
transactions: struct.list([
|
transactions: struct.list([
|
||||||
struct.tuple([
|
struct.tuple([
|
||||||
struct({
|
struct({
|
||||||
signatures: struct.list([struct.list(['number'])]),
|
signatures: struct.list(['string']),
|
||||||
message: struct({
|
message: struct({
|
||||||
accountKeys: struct.list([struct.list(['number'])]),
|
accountKeys: struct.list(['string']),
|
||||||
header: struct({
|
header: struct({
|
||||||
numRequiredSignatures: 'number',
|
numRequiredSignatures: 'number',
|
||||||
numReadonlySignedAccounts: 'number',
|
numReadonlySignedAccounts: 'number',
|
||||||
@ -455,17 +455,13 @@ export const GetConfirmedBlockRpcResult = jsonRpcResult(
|
|||||||
struct.union([
|
struct.union([
|
||||||
struct.list(['number']),
|
struct.list(['number']),
|
||||||
struct({
|
struct({
|
||||||
accounts: struct.list([
|
accounts: struct.list(['number']),
|
||||||
struct.union([struct.list(['number']), 'number']),
|
data: 'string',
|
||||||
]),
|
|
||||||
data: struct.list([
|
|
||||||
struct.union([struct.list(['number']), 'number']),
|
|
||||||
]),
|
|
||||||
programIdIndex: 'number',
|
programIdIndex: 'number',
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
recentBlockhash: struct.list(['number']),
|
recentBlockhash: 'string',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
struct.union([
|
struct.union([
|
||||||
|
@ -21,7 +21,7 @@ export type TransactionSignature = string;
|
|||||||
*
|
*
|
||||||
* Signatures are 64 bytes in length
|
* Signatures are 64 bytes in length
|
||||||
*/
|
*/
|
||||||
const DEFAULT_SIGNATURE = Array(64).fill(0);
|
const DEFAULT_SIGNATURE = Buffer.alloc(64).fill(0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum over-the-wire size of a Transaction
|
* Maximum over-the-wire size of a Transaction
|
||||||
@ -489,7 +489,7 @@ export class Transaction {
|
|||||||
for (let i = 0; i < signatureCount; i++) {
|
for (let i = 0; i < signatureCount; i++) {
|
||||||
const signature = byteArray.slice(0, SIGNATURE_LENGTH);
|
const signature = byteArray.slice(0, SIGNATURE_LENGTH);
|
||||||
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
||||||
signatures.push(signature);
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const numRequiredSignatures = byteArray.shift();
|
const numRequiredSignatures = byteArray.shift();
|
||||||
@ -504,7 +504,7 @@ export class Transaction {
|
|||||||
for (let i = 0; i < accountCount; i++) {
|
for (let i = 0; i < accountCount; i++) {
|
||||||
const account = byteArray.slice(0, PUBKEY_LENGTH);
|
const account = byteArray.slice(0, PUBKEY_LENGTH);
|
||||||
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
||||||
accounts.push(account);
|
accounts.push(bs58.encode(Buffer.from(account)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
|
const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
|
||||||
@ -519,7 +519,8 @@ export class Transaction {
|
|||||||
instruction.accounts = byteArray.slice(0, accountCount);
|
instruction.accounts = byteArray.slice(0, accountCount);
|
||||||
byteArray = byteArray.slice(accountCount);
|
byteArray = byteArray.slice(accountCount);
|
||||||
const dataLength = shortvec.decodeLength(byteArray);
|
const dataLength = shortvec.decodeLength(byteArray);
|
||||||
instruction.data = byteArray.slice(0, dataLength);
|
const data = byteArray.slice(0, dataLength);
|
||||||
|
instruction.data = bs58.encode(Buffer.from(data));
|
||||||
byteArray = byteArray.slice(dataLength);
|
byteArray = byteArray.slice(dataLength);
|
||||||
instructions.push(instruction);
|
instructions.push(instruction);
|
||||||
}
|
}
|
||||||
@ -539,13 +540,9 @@ export class Transaction {
|
|||||||
* Parse an RPC result into a Transaction object.
|
* Parse an RPC result into a Transaction object.
|
||||||
*/
|
*/
|
||||||
static fromRpcResult(rpcResult: any): Transaction {
|
static fromRpcResult(rpcResult: any): Transaction {
|
||||||
const signatures = rpcResult.signatures.slice(1);
|
const signatures = rpcResult.signatures;
|
||||||
const accounts = rpcResult.message.accountKeys.slice(1);
|
const accounts = rpcResult.message.accountKeys;
|
||||||
const instructions = rpcResult.message.instructions.slice(1).map(ix => {
|
const instructions = rpcResult.message.instructions;
|
||||||
ix.accounts.shift();
|
|
||||||
ix.data.shift();
|
|
||||||
return ix;
|
|
||||||
});
|
|
||||||
const recentBlockhash = rpcResult.message.recentBlockhash;
|
const recentBlockhash = rpcResult.message.recentBlockhash;
|
||||||
const numRequiredSignatures =
|
const numRequiredSignatures =
|
||||||
rpcResult.message.header.numRequiredSignatures;
|
rpcResult.message.header.numRequiredSignatures;
|
||||||
@ -569,8 +566,8 @@ export class Transaction {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
static _populate(
|
static _populate(
|
||||||
signatures: Array<Array<number>>,
|
signatures: Array<string>,
|
||||||
accounts: Array<Array<number>>,
|
accounts: Array<string>,
|
||||||
instructions: Array<any>,
|
instructions: Array<any>,
|
||||||
recentBlockhash: Array<number>,
|
recentBlockhash: Array<number>,
|
||||||
numRequiredSignatures: number,
|
numRequiredSignatures: number,
|
||||||
@ -596,9 +593,9 @@ export class Transaction {
|
|||||||
for (let i = 0; i < signatures.length; i++) {
|
for (let i = 0; i < signatures.length; i++) {
|
||||||
const sigPubkeyPair = {
|
const sigPubkeyPair = {
|
||||||
signature:
|
signature:
|
||||||
signatures[i].toString() == DEFAULT_SIGNATURE.toString()
|
signatures[i] == bs58.encode(DEFAULT_SIGNATURE)
|
||||||
? null
|
? null
|
||||||
: Buffer.from(signatures[i]),
|
: bs58.decode(signatures[i]),
|
||||||
publicKey: new PublicKey(accounts[i]),
|
publicKey: new PublicKey(accounts[i]),
|
||||||
};
|
};
|
||||||
transaction.signatures.push(sigPubkeyPair);
|
transaction.signatures.push(sigPubkeyPair);
|
||||||
@ -607,7 +604,7 @@ export class Transaction {
|
|||||||
let instructionData = {
|
let instructionData = {
|
||||||
keys: [],
|
keys: [],
|
||||||
programId: new PublicKey(accounts[instructions[i].programIndex]),
|
programId: new PublicKey(accounts[instructions[i].programIndex]),
|
||||||
data: Buffer.from(instructions[i].data),
|
data: bs58.decode(instructions[i].data),
|
||||||
};
|
};
|
||||||
for (let j = 0; j < instructions[i].accounts.length; j++) {
|
for (let j = 0; j < instructions[i].accounts.length; j++) {
|
||||||
const pubkey = new PublicKey(accounts[instructions[i].accounts[j]]);
|
const pubkey = new PublicKey(accounts[instructions[i].accounts[j]]);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
import bs58 from 'bs58';
|
||||||
import nacl from 'tweetnacl';
|
import nacl from 'tweetnacl';
|
||||||
|
|
||||||
import {Account} from '../src/account';
|
import {Account} from '../src/account';
|
||||||
@ -155,12 +156,11 @@ test('transaction from rpc result', () => {
|
|||||||
const rpcResult = {
|
const rpcResult = {
|
||||||
message: {
|
message: {
|
||||||
accountKeys: [
|
accountKeys: [
|
||||||
[5],
|
new PublicKey(1).toString(),
|
||||||
new PublicKey(1).toBuffer(),
|
new PublicKey(2).toString(),
|
||||||
new PublicKey(2).toBuffer(),
|
new PublicKey(3).toString(),
|
||||||
new PublicKey(3).toBuffer(),
|
new PublicKey(4).toString(),
|
||||||
new PublicKey(4).toBuffer(),
|
new PublicKey(5).toString(),
|
||||||
new PublicKey(5).toBuffer(),
|
|
||||||
],
|
],
|
||||||
header: {
|
header: {
|
||||||
num_ReadonlySignedAccounts: 0,
|
num_ReadonlySignedAccounts: 0,
|
||||||
@ -168,16 +168,18 @@ test('transaction from rpc result', () => {
|
|||||||
numRequiredSignatures: 2,
|
numRequiredSignatures: 2,
|
||||||
},
|
},
|
||||||
instructions: [
|
instructions: [
|
||||||
[1],
|
|
||||||
{
|
{
|
||||||
accounts: [[3], 1, 2, 3],
|
accounts: [1, 2, 3],
|
||||||
data: [[1], 0],
|
data: bs58.encode(Buffer.alloc(5).fill(9)),
|
||||||
programIdIndex: 4,
|
programIdIndex: 4,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
recentBlockhash: rawBlockhash,
|
recentBlockhash: rawBlockhash,
|
||||||
},
|
},
|
||||||
signatures: [[2], Array(64).fill(1), Array(64).fill(2)],
|
signatures: [
|
||||||
|
bs58.encode(Buffer.alloc(64).fill(1)),
|
||||||
|
bs58.encode(Buffer.alloc(64).fill(2)),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const recentBlockhash = new PublicKey(rawBlockhash).toBase58();
|
const recentBlockhash = new PublicKey(rawBlockhash).toBase58();
|
||||||
|
Reference in New Issue
Block a user