UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

51 lines (50 loc) 2.65 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { address } from '@solana/addresses'; import { createTransactionMessage } from '@solana/transaction-messages'; import { setTransactionMessageFeePayer } from '@solana/transaction-messages'; import { setTransactionMessageLifetimeUsingBlockhash } from '@solana/transaction-messages'; import { appendTransactionMessageInstruction } from '@solana/transaction-messages'; import { compileTransaction, signTransaction } from '@solana/transactions'; import { pipe } from '@solana/functional'; /** * Create and sign a transaction from instructions and feePayer. * Automatically fetches recentBlockhash and lastValidBlockHeight. */ export function createTransaction(_a) { return __awaiter(this, arguments, void 0, function* ({ connection, instructions, feePayer, signers }) { const result = yield connection.request('getLatestBlockhash', []); const { blockhash, lastValidBlockHeight } = result; const msg = pipe(createTransactionMessage({ version: 0 }), m => setTransactionMessageFeePayer(typeof feePayer === 'string' ? address(feePayer) : feePayer, m), m => setTransactionMessageLifetimeUsingBlockhash({ blockhash: blockhash, // Cast to any to satisfy branded type lastValidBlockHeight: BigInt(lastValidBlockHeight) }, m), m => { let out = m; for (const ix of instructions) { out = appendTransactionMessageInstruction(ix, out); } return out; }); const compiled = compileTransaction(msg); const signed = yield signTransaction(signers, compiled); return signed; }); } /** * Return transaction metadata and raw instructions for UI or API */ export function getTransactionMetadata(tx) { return { signatures: tx.signatures, messageBytes: tx.messageBytes // No direct feePayer/recentBlockhash/instructions on Transaction type in kit }; } export * from './getAndDecodeTransaction.js';