-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing a Transaction Builder for Cardano: Simplify Transaction Creation and Signing
- Loading branch information
1 parent
93fa50f
commit 201f5ac
Showing
21 changed files
with
250 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
example/lib/example/solana/token_program/create_associated_token_account.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:example/example/solana/quick_wallet_for_testing/quick_wallet.dart'; | ||
import 'package:on_chain/solana/solana.dart'; | ||
|
||
void main() async { | ||
final wallet = QuickWalletForTest(index: 1100); | ||
final mintAccount = QuickWalletForTest(index: 1111); | ||
|
||
final associatedTokenAccount = | ||
AssociatedTokenAccountProgramUtils.associatedTokenAccount( | ||
mint: mintAccount.address, owner: wallet.address); | ||
|
||
final createAssociatedTokenAccount = | ||
AssociatedTokenAccountProgram.associatedTokenAccount( | ||
payer: wallet.address, | ||
associatedToken: associatedTokenAccount.address, | ||
owner: wallet.address, | ||
mint: mintAccount.address); | ||
|
||
final tr = SolanaTransaction( | ||
payerKey: wallet.address, | ||
instructions: [createAssociatedTokenAccount], | ||
recentBlockhash: await wallet.recentBlockhash()); | ||
tr.sign([wallet.privateKey]); | ||
await wallet.submitTr(tr.serializeString()); | ||
|
||
/// https://explorer.solana.com/tx/BTdjhKHYKcKFSNdxQXG617JUXbMGnZs54aWZyKGsiPTh6Z6f8Qe1WMZQGD7BbBjfrFrjEmdU8HyQQ9NRQmZHWUP?cluster=testnet | ||
} |
33 changes: 33 additions & 0 deletions
33
example/lib/example/solana/token_program/create_mint_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:example/example/solana/quick_wallet_for_testing/quick_wallet.dart'; | ||
import 'package:on_chain/solana/solana.dart'; | ||
|
||
void main() async { | ||
final wallet = QuickWalletForTest(index: 1100); | ||
final freezeAuthority = QuickWalletForTest(index: 1112); | ||
final mintAccount = QuickWalletForTest(index: 1111); | ||
final mintAccSpace = SolanaMintAccount.size; | ||
final rent = await QuickWalletForTest.rpc | ||
.request(SolanaRPCGetMinimumBalanceForRentExemption(size: mintAccSpace)); | ||
final createAccount = SystemProgram.createAccount( | ||
from: wallet.address, | ||
newAccountPubKey: mintAccount.address, | ||
layout: SystemCreateLayout( | ||
lamports: rent, | ||
space: BigInt.from(mintAccSpace), | ||
programId: SPLTokenProgramConst.tokenProgramId)); | ||
|
||
final mint = SPLTokenProgram.initializeMint2( | ||
layout: SPLTokenInitializeMint2Layout( | ||
mintAuthority: wallet.address, | ||
decimals: 3, | ||
freezeAuthority: freezeAuthority.address), | ||
mint: mintAccount.address); | ||
final tr = SolanaTransaction( | ||
payerKey: wallet.address, | ||
instructions: [createAccount, mint], | ||
recentBlockhash: await wallet.recentBlockhash()); | ||
tr.sign([wallet.privateKey, mintAccount.privateKey]); | ||
await wallet.submitTr(tr.serializeString()); | ||
|
||
/// https://explorer.solana.com/tx/mdjLvhvVUqfBKnmmCRAsmAjXGZsxEWMw7vvZMfT512rjeydmfgDfdX8YZmTjbvxNVqGbSBScedxAGXzfF3GLceR?cluster=testnet | ||
} |
24 changes: 24 additions & 0 deletions
24
example/lib/example/solana/token_program/mint_to_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:example/example/solana/quick_wallet_for_testing/quick_wallet.dart'; | ||
import 'package:on_chain/solana/solana.dart'; | ||
|
||
void main() async { | ||
final wallet = QuickWalletForTest(index: 1100); | ||
final mintAccount = QuickWalletForTest(index: 1111); | ||
final owner = SolAddress("6fLggs5D6iwCMwB5a2Scd3gqPYcvtpvWpFb4LXFQ89Bz"); | ||
final destinationTokenAccount = | ||
AssociatedTokenAccountProgramUtils.associatedTokenAccount( | ||
mint: mintAccount.address, owner: owner); | ||
final createAssociatedTokenAccount = SPLTokenProgram.mintTo( | ||
mint: mintAccount.address, | ||
destination: destinationTokenAccount.address, | ||
authority: wallet.address, | ||
layout: SPLTokenMintToLayout(amount: BigInt.from(123456455345234234))); | ||
final tr = SolanaTransaction( | ||
payerKey: wallet.address, | ||
instructions: [createAssociatedTokenAccount], | ||
recentBlockhash: await wallet.recentBlockhash()); | ||
tr.sign([wallet.privateKey]); | ||
await wallet.submitTr(tr.serializeString()); | ||
|
||
/// https://explorer.solana.com/tx/3BWNp5nkcwQz786WVfZmnTdhiE7c11Sef7YfhmPvmKYWbpp5KEcnYSLwm8xwqK4y2ufgRVHpwiWR39gDR4JYALH8?cluster=testnet | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export 'builder/tranasction_builder_utils.dart'; | ||
export 'builder/transaction_builder.dart'; | ||
export 'builder/mint_builder.dart'; | ||
export 'builder/certificate_builder.dart'; | ||
export 'builder/deposit.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:on_chain/ada/ada.dart'; | ||
|
||
class ADACertificateBuilder { | ||
final Certificate certificate; | ||
final ADAAddress? signer; | ||
const ADACertificateBuilder({required this.certificate, this.signer}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ADADepositBuilder { | ||
final BigInt deposit; | ||
const ADADepositBuilder({required this.deposit}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:blockchain_utils/binary/utils.dart'; | ||
import 'package:on_chain/ada/src/address/era/core/address.dart'; | ||
import 'package:on_chain/ada/src/models/ada_models.dart'; | ||
|
||
class ADAMinsBuilder { | ||
final Assets mintingAssets; | ||
final ADAAddress owner; | ||
final List<int> pubKeyBytes; | ||
ADAMinsBuilder( | ||
{required List<int> pubKeyBytes, | ||
required this.mintingAssets, | ||
required this.owner}) | ||
: pubKeyBytes = BytesUtils.toBytes(pubKeyBytes); | ||
PolicyID toPolicyId() { | ||
return PolicyID(toScript().toHash().data); | ||
} | ||
|
||
MultiAsset toMultiAssets() => MultiAsset({toPolicyId(): mintingAssets}); | ||
|
||
NativeScriptScriptPubkey toScript() { | ||
final publickKey = Ed25519KeyHash.fromPubkey(pubKeyBytes); | ||
return NativeScriptScriptPubkey(publickKey); | ||
} | ||
|
||
MintAssets toMintAsset() { | ||
return MintAssets(mintingAssets.assets); | ||
} | ||
|
||
MintInfo toMintInfo() { | ||
return MintInfo(policyID: toPolicyId(), assets: toMintAsset()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.