Skip to content

Commit

Permalink
refactor: ♻️ Rename Tx serialization for blockchain node.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralu committed Dec 10, 2024
1 parent 33ea5f8 commit 2d3d7e9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main(List<String> args) {
)
.build('mysuperpassphraseorseed', 0, curve: 'P256')
.transaction
..convertToJSON();
..toNodeRPC();

/// Sign the transaction with an origin device private key
final originKeypair = deriveKeyPair('origin_seed', 0, isSeedHexa: false);
Expand All @@ -39,7 +39,7 @@ void main(List<String> args) {
uint8ListToHex(
Uint8List.fromList(originKeypair.privateKey!),
),
)..convertToJSON();
)..toNodeRPC();

/// Export the transaction generated into JSON
final transaction3 = Transaction(
Expand All @@ -52,5 +52,5 @@ void main(List<String> args) {
)
.build('mysuperpassphraseorseed', 0, curve: 'P256')
.transaction
..convertToJSON();
..toNodeRPC();
}
2 changes: 1 addition & 1 deletion lib/src/model/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class Transaction with _$Transaction {
}

/// Convert the transaction in JSON
String convertToJSON() {
String toNodeRPC() {
final json = jsonEncode(<String, Object?>{
'version': version,
'address': address == null ? '' : address!.address,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/services/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ApiService with JsonRPCUtil {
'send_transaction',
{
'transaction': jsonDecode(
transaction.convertToJSON(),
transaction.toNodeRPC(),
),
},
);
Expand Down Expand Up @@ -495,7 +495,7 @@ class ApiService with JsonRPCUtil {
'estimate_transaction_fee',
{
'transaction': jsonDecode(
transaction.convertToJSON(),
transaction.toNodeRPC(),
),
},
);
Expand Down
8 changes: 4 additions & 4 deletions test/keychain_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void main() {
derivationPath: kDerivationPath,
);
dev.log(
'keychainTransaction: ${keychainTransaction.convertToJSON()}',
'keychainTransaction: ${keychainTransaction.toNodeRPC()}',
);

/// Create Keychain Access for wallet
Expand All @@ -219,7 +219,7 @@ void main() {
Uint8List.fromList(hexToUint8List(originPrivateKey)),
blockchainTxVersion,
);
dev.log('accessKeychainTx: ${accessKeychainTx.convertToJSON()}');
dev.log('accessKeychainTx: ${accessKeychainTx.toNodeRPC()}');

// ignore: unused_local_variable
final transactionStatusKeychain =
Expand Down Expand Up @@ -361,7 +361,7 @@ void main() {
derivationPath: kDerivationPath,
);
dev.log(
'keychainTransaction: ${keychainTransaction.convertToJSON()}',
'keychainTransaction: ${keychainTransaction.toNodeRPC()}',
);

/// Create Keychain Access for wallet
Expand All @@ -374,7 +374,7 @@ void main() {
Uint8List.fromList(hexToUint8List(originPrivateKey)),
blockchainTxVersion,
);
dev.log('accessKeychainTx: ${accessKeychainTx.convertToJSON()}');
dev.log('accessKeychainTx: ${accessKeychainTx.toNodeRPC()}');

// ignore: unused_local_variable
final transactionStatusKeychain =
Expand Down
4 changes: 2 additions & 2 deletions test/transaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void main() {
])
.build('seed', 0, curve: 'P256', isSeedHexa: false)
.transaction;
final dynamic parsedTx = json.decode(tx.convertToJSON());
final dynamic parsedTx = json.decode(tx.toNodeRPC());
expect(
parsedTx['data']['ownerships'][0]['authorizedKeys'],
<Map<String, String>>[
Expand Down Expand Up @@ -693,7 +693,7 @@ condition inherit: [
uint8ListToHex(Uint8List.fromList(originKeypair.privateKey!)),
);

final Map<String, dynamic> parsedTx = json.decode(tx.convertToJSON());
final Map<String, dynamic> parsedTx = json.decode(tx.toNodeRPC());

final previousSig = crypto.sign(
tx.previousSignaturePayload(),
Expand Down

0 comments on commit 2d3d7e9

Please sign in to comment.