Open gBaGu opened 2 years ago
Add possibility to generate Borsh schema for Typescript. See velas evm generate-borsh-schema for generation
velas evm generate-borsh-schema
Ts code generated from current instructions:
import { PublicKey } from "@solana/web3.js"; import BN from "bn.js"; import Enum from "./extensions/enum"; import Struct from "./extensions/struct"; import { borshPublicKey } from "./extensions/publicKey"; borshPublicKey(); export class Transaction extends Struct { nonce: U256; gasPrice: Gas; gasLimit: Gas; action: TransactionAction; value: U256; signature: TransactionSignature; input: number[]; }; export class UnsignedTransaction extends Struct { nonce: U256; gasPrice: U256; gasLimit: U256; action: TransactionAction; value: U256; input: number[]; }; export class TransactionAction extends Enum { transactionActionCall: TransactionActionCall; transactionActionCreate: TransactionActionCreate; }; export class TransactionActionCall extends Struct { unnamed_0: Address; }; export class TransactionActionCreate extends Struct { }; export class TransactionSignature extends Struct { v: BN; r: H256; s: H256; }; export class FeePayerType extends Enum { feePayerTypeEvm: FeePayerTypeEvm; feePayerTypeNative: FeePayerTypeNative; }; export class FeePayerTypeEvm extends Struct { }; export class FeePayerTypeNative extends Struct { }; export class EvmBigTransaction extends Enum { evmBigTransactionEvmTransactionAllocate: EvmBigTransactionEvmTransactionAllocate; evmBigTransactionEvmTransactionWrite: EvmBigTransactionEvmTransactionWrite; }; export class EvmBigTransactionEvmTransactionAllocate extends Struct { size: BN; }; export class EvmBigTransactionEvmTransactionWrite extends Struct { offset: BN; data: number[]; }; export class ExecuteTransaction extends Enum { executeTransactionSigned: ExecuteTransactionSigned; executeTransactionProgramAuthorized: ExecuteTransactionProgramAuthorized; }; export class ExecuteTransactionSigned extends Struct { tx: Transaction | null; }; export class ExecuteTransactionProgramAuthorized extends Struct { tx: UnsignedTransaction | null; from: evm::Address; }; export class EvmInstruction extends Enum { evmInstructionSwapNativeToEther: EvmInstructionSwapNativeToEther; evmInstructionFreeOwnership: EvmInstructionFreeOwnership; evmInstructionEvmBigTransaction: EvmInstructionEvmBigTransaction; evmInstructionExecuteTransaction: EvmInstructionExecuteTransaction; }; export class EvmInstructionSwapNativeToEther extends Struct { lamports: BN; evmAddress: evm::Address; }; export class EvmInstructionFreeOwnership extends Struct { }; export class EvmInstructionEvmBigTransaction extends Struct { unnamed_0: EvmBigTransaction; }; export class EvmInstructionExecuteTransaction extends Struct { tx: ExecuteTransaction; feeType: FeePayerType; }; export const SCHEMA = new Map<any, any>([ [ Transaction, { kind: 'struct', fields: [ ['nonce', U256], ['gasPrice', Gas], ['gasLimit', Gas], ['action', TransactionAction], ['value', U256], ['signature', TransactionSignature], ['input', ['u8']], ], }, ], [ UnsignedTransaction, { kind: 'struct', fields: [ ['nonce', U256], ['gasPrice', U256], ['gasLimit', U256], ['action', TransactionAction], ['value', U256], ['input', ['u8']], ], }, ], [ TransactionAction, { kind: 'enum', field: 'enum', values: [ ['transactionActionCall', TransactionActionCall], ['transactionActionCreate', TransactionActionCreate], ], }, ], [ TransactionActionCall, { kind: 'struct', fields: [ ['unnamed_0', Address], ], }, ], [ TransactionActionCreate, { kind: 'struct', fields: [ ], }, ], [ TransactionSignature, { kind: 'struct', fields: [ ['v', 'u64'], ['r', H256], ['s', H256], ], }, ], [ FeePayerType, { kind: 'enum', field: 'enum', values: [ ['feePayerTypeEvm', FeePayerTypeEvm], ['feePayerTypeNative', FeePayerTypeNative], ], }, ], [ FeePayerTypeEvm, { kind: 'struct', fields: [ ], }, ], [ FeePayerTypeNative, { kind: 'struct', fields: [ ], }, ], [ EvmBigTransaction, { kind: 'enum', field: 'enum', values: [ ['evmBigTransactionEvmTransactionAllocate', EvmBigTransactionEvmTransactionAllocate], ['evmBigTransactionEvmTransactionWrite', EvmBigTransactionEvmTransactionWrite], ], }, ], [ EvmBigTransactionEvmTransactionAllocate, { kind: 'struct', fields: [ ['size', 'u64'], ], }, ], [ EvmBigTransactionEvmTransactionWrite, { kind: 'struct', fields: [ ['offset', 'u64'], ['data', ['u8']], ], }, ], [ ExecuteTransaction, { kind: 'enum', field: 'enum', values: [ ['executeTransactionSigned', ExecuteTransactionSigned], ['executeTransactionProgramAuthorized', ExecuteTransactionProgramAuthorized], ], }, ], [ ExecuteTransactionSigned, { kind: 'struct', fields: [ ['tx', { kind: 'option', type: Transaction }], ], }, ], [ ExecuteTransactionProgramAuthorized, { kind: 'struct', fields: [ ['tx', { kind: 'option', type: UnsignedTransaction }], ['from', evm::Address], ], }, ], [ EvmInstruction, { kind: 'enum', field: 'enum', values: [ ['evmInstructionSwapNativeToEther', EvmInstructionSwapNativeToEther], ['evmInstructionFreeOwnership', EvmInstructionFreeOwnership], ['evmInstructionEvmBigTransaction', EvmInstructionEvmBigTransaction], ['evmInstructionExecuteTransaction', EvmInstructionExecuteTransaction], ], }, ], [ EvmInstructionSwapNativeToEther, { kind: 'struct', fields: [ ['lamports', 'u64'], ['evmAddress', evm::Address], ], }, ], [ EvmInstructionFreeOwnership, { kind: 'struct', fields: [ ], }, ], [ EvmInstructionEvmBigTransaction, { kind: 'struct', fields: [ ['unnamed_0', EvmBigTransaction], ], }, ], [ EvmInstructionExecuteTransaction, { kind: 'struct', fields: [ ['tx', ExecuteTransaction], ['feeType', FeePayerType], ], }, ], ]);
Add possibility to generate Borsh schema for Typescript. See
velas evm generate-borsh-schema
for generationTs code generated from current instructions: