Skip to content

Commit

Permalink
V4.2.0
Browse files Browse the repository at this point in the history
- Fixed Solana simulate transaction model
- Added helper methods to solana versioned messages for replacing blockchains
  • Loading branch information
mrtnetwork committed Sep 18, 2024
1 parent bcb3f29 commit 2245d38
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class SimulateTranasctionReturnDataResponse {
}

class SimulateTranasctionResponse {
final String? err;
final dynamic err;
final List<String>? logs;
final List<SolanaAccountInfo>? accounts;
final List<SolanaAccountInfo?>? accounts;
final BigInt? unitsConsumed;
final SimulateTranasctionReturnDataResponse? returnData;
final CompiledInnerInstruction? innerInstructions;
Expand All @@ -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()
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/solana/src/transaction/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class TransactionType {

/// Abstract class representing a versioned message.
abstract class VersionedMessage {
VersionedMessage copyWith(
{MessageHeader? header,
List<SolAddress>? accountKeys,
SolAddress? recentBlockhash,
List<CompiledInstruction>? compiledInstructions,
List<AddressTableLookup>? addressTableLookups});

/// The message header, identifying signed and read-only [accountKeys].
abstract final MessageHeader header;

Expand Down
15 changes: 15 additions & 0 deletions lib/solana/src/transaction/message/legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ class Message implements VersionedMessage {
required this.compiledInstructions,
});

@override
Message copyWith(
{MessageHeader? header,
List<SolAddress>? accountKeys,
SolAddress? recentBlockhash,
List<CompiledInstruction>? compiledInstructions,
List<AddressTableLookup>? 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<int> buffer) {
return SolanaTransactionUtils.deserializeMessageLegacy(buffer);
Expand Down
15 changes: 15 additions & 0 deletions lib/solana/src/transaction/message/message_v0.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ class MessageV0 implements VersionedMessage {
required this.addressTableLookups,
});

@override
MessageV0 copyWith(
{MessageHeader? header,
List<SolAddress>? accountKeys,
SolAddress? recentBlockhash,
List<CompiledInstruction>? compiledInstructions,
List<AddressTableLookup>? 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<TransactionInstruction> transactionInstructions,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2245d38

Please sign in to comment.