diff --git a/CHANGELOG.md b/CHANGELOG.md index 724a60e..20197e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -# 4.1.0 +## 4.2.0 + +- Fixed Solana simulate transaction model +- Added helper methods to solana versioned messages for replacing blockchains + +## 4.1.0 - Fix Solana pre-instruction serialization issues diff --git a/lib/solana/src/rpc/models/models/simulate_transaction_response.dart b/lib/solana/src/rpc/models/models/simulate_transaction_response.dart index d104978..b086df1 100644 --- a/lib/solana/src/rpc/models/models/simulate_transaction_response.dart +++ b/lib/solana/src/rpc/models/models/simulate_transaction_response.dart @@ -20,9 +20,9 @@ class SimulateTranasctionReturnDataResponse { } class SimulateTranasctionResponse { - final String? err; + final dynamic err; final List? logs; - final List? accounts; + final List? accounts; final BigInt? unitsConsumed; final SimulateTranasctionReturnDataResponse? returnData; final CompiledInnerInstruction? innerInstructions; @@ -31,7 +31,7 @@ class SimulateTranasctionResponse { return { "err": err, "logs": logs, - "accounts": accounts?.map((e) => e.toJson()).toList(), + "accounts": accounts?.map((e) => e?.toJson()).toList(), "unitsConsumed": unitsConsumed?.toString(), "returnData": returnData?.toJson(), "innerInstructions": innerInstructions?.toJson() @@ -49,9 +49,10 @@ class SimulateTranasctionResponse { return SimulateTranasctionResponse( err: json["err"], logs: (json["logs"] as List?)?.map((e) => e.toString()).toList(), - accounts: (json["accounts"] as List?) - ?.map((e) => SolanaAccountInfo.fromJson((e as Map).cast())) - .toList(), + accounts: (json["accounts"] as List?)?.map((e) { + if (e == null) return null; + return SolanaAccountInfo.fromJson((e as Map).cast()); + }).toList(), unitsConsumed: BigintUtils.tryParse(json["unitsConsumed"]), returnData: json["returnData"] == null ? null diff --git a/lib/solana/src/transaction/core/core.dart b/lib/solana/src/transaction/core/core.dart index 4856a2d..1c3ae7f 100644 --- a/lib/solana/src/transaction/core/core.dart +++ b/lib/solana/src/transaction/core/core.dart @@ -39,6 +39,13 @@ class TransactionType { /// Abstract class representing a versioned message. abstract class VersionedMessage { + VersionedMessage copyWith( + {MessageHeader? header, + List? accountKeys, + SolAddress? recentBlockhash, + List? compiledInstructions, + List? addressTableLookups}); + /// The message header, identifying signed and read-only [accountKeys]. abstract final MessageHeader header; diff --git a/lib/solana/src/transaction/message/legacy.dart b/lib/solana/src/transaction/message/legacy.dart index 846c413..85d03b7 100644 --- a/lib/solana/src/transaction/message/legacy.dart +++ b/lib/solana/src/transaction/message/legacy.dart @@ -30,6 +30,21 @@ class Message implements VersionedMessage { required this.compiledInstructions, }); + @override + Message copyWith( + {MessageHeader? header, + List? accountKeys, + SolAddress? recentBlockhash, + List? compiledInstructions, + List? addressTableLookups}) { + return Message( + header: header ?? this.header, + accountKeys: accountKeys ?? this.accountKeys, + recentBlockhash: recentBlockhash ?? this.recentBlockhash, + compiledInstructions: + compiledInstructions ?? this.compiledInstructions); + } + /// Constructs a message from a serialized buffer. factory Message.fromBuffer(List buffer) { return SolanaTransactionUtils.deserializeMessageLegacy(buffer); diff --git a/lib/solana/src/transaction/message/message_v0.dart b/lib/solana/src/transaction/message/message_v0.dart index a4c7329..6c01bcf 100644 --- a/lib/solana/src/transaction/message/message_v0.dart +++ b/lib/solana/src/transaction/message/message_v0.dart @@ -34,6 +34,21 @@ class MessageV0 implements VersionedMessage { required this.addressTableLookups, }); + @override + MessageV0 copyWith( + {MessageHeader? header, + List? accountKeys, + SolAddress? recentBlockhash, + List? compiledInstructions, + List? addressTableLookups}) { + return MessageV0( + header: header ?? this.header, + accountKeys: accountKeys ?? this.accountKeys, + recentBlockhash: recentBlockhash ?? this.recentBlockhash, + compiledInstructions: compiledInstructions ?? this.compiledInstructions, + addressTableLookups: addressTableLookups ?? this.addressTableLookups); + } + /// Compiles a version 0 message from provided parameters. factory MessageV0.compile({ required List transactionInstructions, diff --git a/pubspec.yaml b/pubspec.yaml index 64fcb6d..5460dad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: on_chain description: Streamline Ethereum, Tron, Solana and Cardano operations. Effortlessly create transactions, interact with smart contracts, sign, and send transactions. -version: 4.1.0 +version: 4.2.0 homepage: "https://github.com/mrtnetwork/on_chain" repository: "https://github.com/mrtnetwork/on_chain" Author: mrhaydari.t@gmail.com