UNPKG

@dbricks/dbricks-ts

Version:

## Introduction

85 lines (84 loc) 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deserializeInstructionsAndSigners = exports.serializeInstructionsAndSigners = exports.deserializeSigners = exports.serializeSigners = exports.deserializeInstructions = exports.serializeInstructions = exports.deserializePubkey = exports.serializePubkey = void 0; const web3_js_1 = require("@solana/web3.js"); function serializePubkey(pubkey) { return pubkey.toBase58(); } exports.serializePubkey = serializePubkey; function deserializePubkey(pubkey) { return new web3_js_1.PublicKey(pubkey); } exports.deserializePubkey = deserializePubkey; function serializeInstructions(instructions) { const serializedInstruction = []; instructions.forEach((instruction) => { const newInstruction = { keys: [], programId: serializePubkey(instruction.programId), data: instruction.data.toString('hex'), }; instruction.keys.forEach((k) => { newInstruction.keys.push({ pubkey: serializePubkey(k.pubkey), isSigner: k.isSigner, isWritable: k.isWritable }); }); serializedInstruction.push(newInstruction); }); return serializedInstruction; } exports.serializeInstructions = serializeInstructions; function deserializeInstructions(instructions) { const deserializedInstructions = []; instructions.forEach((instruction) => { const newInstruction = { keys: [], programId: deserializePubkey(instruction.programId), data: Buffer.from(instruction.data, 'hex'), }; instruction.keys.forEach((k) => { newInstruction.keys.push({ pubkey: deserializePubkey(k.pubkey), isSigner: k.isSigner, isWritable: k.isWritable }); }); deserializedInstructions.push(newInstruction); }); return deserializedInstructions; } exports.deserializeInstructions = deserializeInstructions; function serializeSigners(signers) { const serializedSigners = []; signers.forEach((s) => { serializedSigners.push({ secretKey: Array.from(s.secretKey), }); }); return serializedSigners; } exports.serializeSigners = serializeSigners; function deserializeSigners(signers) { const deserializedSigners = []; signers.forEach((s) => { deserializedSigners.push(web3_js_1.Keypair.fromSecretKey(new Uint8Array(s.secretKey))); }); return deserializedSigners; } exports.deserializeSigners = deserializeSigners; function serializeInstructionsAndSigners(transactions) { const serializedTransactions = []; transactions.forEach((transaction) => { serializedTransactions.push({ instructions: serializeInstructions(transaction.instructions), signers: serializeSigners(transaction.signers), }); }); return serializedTransactions; } exports.serializeInstructionsAndSigners = serializeInstructionsAndSigners; function deserializeInstructionsAndSigners(transactions) { const deserializedTransactions = []; transactions.forEach((transaction) => { deserializedTransactions.push({ instructions: deserializeInstructions(transaction.instructions), signers: deserializeSigners(transaction.signers), }); }); return deserializedTransactions; } exports.deserializeInstructionsAndSigners = deserializeInstructionsAndSigners;