From f4c3c9dcd0caf89a61733bb8258b6382c03d3fc6 Mon Sep 17 00:00:00 2001 From: darkverbito Date: Mon, 27 Nov 2023 13:08:34 -0600 Subject: [PATCH] Add example to README (#130) --- README.md | 33 +++++++++++++++++++ bin/chia_crypto_utils.dart | 2 +- .../enhanced_chia_full_node_interface.dart | 3 ++ .../full_node/chia_full_node_interface.dart | 15 ++++++++- .../service/wallet_client/cold_wallet.dart | 2 +- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 31e90b21..37fde74e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,39 @@ simulator_gen_path.json } ``` +## Example +```dart + // Initialize keychain +const mnemonic = 'abandon broom kind...'; + +final keychainSecret = KeychainCoreSecret.fromMnemonicString(mnemonic); + +final keychain = WalletKeychain.fromCoreSecret( + keychainSecret, + walletSize: 50, +); + +// Initialize full node +final certBytes = File('CERT_PATH').readAsBytesSync(); +final keyBytes = File('KEY_PATH').readAsBytesSync(); + +final fullNode = ChiaFullNodeInterface.fromURL( + 'FULL_NODE_URL', + certBytes: Bytes(certBytes), + keyBytes: Bytes(keyBytes), +); + +final wallet = ColdWallet( + fullNode: fullNode, + keychain: keychain, +); + +await wallet.sendXch( + Address('RECEIVER_ADDRESS').toPuzzlehash(), + amount: 1000000000, +); +``` + ## Coverage ### Dependencies diff --git a/bin/chia_crypto_utils.dart b/bin/chia_crypto_utils.dart index 12bda22a..2f8d1453 100644 --- a/bin/chia_crypto_utils.dart +++ b/bin/chia_crypto_utils.dart @@ -832,7 +832,7 @@ class TransferDidCommand extends Command> { final coins = await fullNode.getCoinsByPuzzleHashes(keychain.puzzlehashes); final dids = currentDidAddress != null ? await fullNode.getDidRecordsFromHint(currentDidAddress.toPuzzlehash()) - : await fullNode.getDidRecordsFromHints(keychain.puzzlehashes); + : await fullNode.getDidRecordsByHints(keychain.puzzlehashes); final coinsForFee = () { try { diff --git a/lib/src/api/enhanced_full_node/enhanced_chia_full_node_interface.dart b/lib/src/api/enhanced_full_node/enhanced_chia_full_node_interface.dart index 26c9645c..81d1afef 100644 --- a/lib/src/api/enhanced_full_node/enhanced_chia_full_node_interface.dart +++ b/lib/src/api/enhanced_full_node/enhanced_chia_full_node_interface.dart @@ -142,6 +142,7 @@ class EnhancedChiaFullNodeInterface extends ChiaFullNodeInterface { ); } + @override Future> getNftRecordsByHints( List hints, { int? startHeight, @@ -182,6 +183,7 @@ class EnhancedChiaFullNodeInterface extends ChiaFullNodeInterface { return nfts; } + @override Future> getCatCoinsByHints( List hints, { int? startHeight, @@ -224,6 +226,7 @@ class EnhancedChiaFullNodeInterface extends ChiaFullNodeInterface { ); } + @override Future> getDidRecordsByHints(List hints) async { final coins = await getCoinsByHints(hints); return getDidsFromCoins(coins); diff --git a/lib/src/api/full_node/chia_full_node_interface.dart b/lib/src/api/full_node/chia_full_node_interface.dart index af6350b4..e5d586df 100644 --- a/lib/src/api/full_node/chia_full_node_interface.dart +++ b/lib/src/api/full_node/chia_full_node_interface.dart @@ -171,6 +171,11 @@ class ChiaFullNodeInterface { return getNftRecordsFromCoins(coins); } + Future> getNftRecordsByHints(List hints) async { + final coins = await getCoinsByHints(hints); + return getNftRecordsFromCoins(coins); + } + Future> getNftRecordsFromCoins(List coins) async { final nfts = []; @@ -201,7 +206,7 @@ class ChiaFullNodeInterface { return matches.single; } - Future> getDidRecordsFromHints(List hints) async { + Future> getDidRecordsByHints(List hints) async { final coins = await getCoinsByHints(hints); final didInfos = await getDidsFromCoins(coins); return didInfos; @@ -371,6 +376,14 @@ class ChiaFullNodeInterface { return coinSpendResponse.coinSpend; } + Future> getCatCoinsByHints( + List hints, + ) async { + final coins = await getCoinsByHints(hints); + + return hydrateCatCoins(coins); + } + Future> getCatCoinsByHint( Puzzlehash hint, ) async { diff --git a/lib/src/api/wallet_connect/service/wallet_client/cold_wallet.dart b/lib/src/api/wallet_connect/service/wallet_client/cold_wallet.dart index 524f78ca..b949a571 100644 --- a/lib/src/api/wallet_connect/service/wallet_client/cold_wallet.dart +++ b/lib/src/api/wallet_connect/service/wallet_client/cold_wallet.dart @@ -7,7 +7,7 @@ class ColdWallet implements Wallet { }); @override - final EnhancedChiaFullNodeInterface fullNode; + final ChiaFullNodeInterface fullNode; final WalletKeychain keychain; @override