Skip to content

Commit

Permalink
Add example to README (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkverbito authored Nov 27, 2023
1 parent 4061ab1 commit f4c3c9d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/chia_crypto_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ class TransferDidCommand extends Command<Future<void>> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class EnhancedChiaFullNodeInterface extends ChiaFullNodeInterface {
);
}

@override
Future<List<NftRecord>> getNftRecordsByHints(
List<Puzzlehash> hints, {
int? startHeight,
Expand Down Expand Up @@ -182,6 +183,7 @@ class EnhancedChiaFullNodeInterface extends ChiaFullNodeInterface {
return nfts;
}

@override
Future<List<CatFullCoin>> getCatCoinsByHints(
List<Puzzlehash> hints, {
int? startHeight,
Expand Down Expand Up @@ -224,6 +226,7 @@ class EnhancedChiaFullNodeInterface extends ChiaFullNodeInterface {
);
}

@override
Future<List<DidRecord>> getDidRecordsByHints(List<Puzzlehash> hints) async {
final coins = await getCoinsByHints(hints);
return getDidsFromCoins(coins);
Expand Down
15 changes: 14 additions & 1 deletion lib/src/api/full_node/chia_full_node_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ class ChiaFullNodeInterface {
return getNftRecordsFromCoins(coins);
}

Future<List<NftRecord>> getNftRecordsByHints(List<Puzzlehash> hints) async {
final coins = await getCoinsByHints(hints);
return getNftRecordsFromCoins(coins);
}

Future<List<NftRecord>> getNftRecordsFromCoins(List<Coin> coins) async {
final nfts = <NftRecord>[];

Expand Down Expand Up @@ -201,7 +206,7 @@ class ChiaFullNodeInterface {
return matches.single;
}

Future<List<DidRecord>> getDidRecordsFromHints(List<Puzzlehash> hints) async {
Future<List<DidRecord>> getDidRecordsByHints(List<Puzzlehash> hints) async {
final coins = await getCoinsByHints(hints);
final didInfos = await getDidsFromCoins(coins);
return didInfos;
Expand Down Expand Up @@ -371,6 +376,14 @@ class ChiaFullNodeInterface {
return coinSpendResponse.coinSpend;
}

Future<List<CatFullCoin>> getCatCoinsByHints(
List<Puzzlehash> hints,
) async {
final coins = await getCoinsByHints(hints);

return hydrateCatCoins(coins);
}

Future<List<CatFullCoin>> getCatCoinsByHint(
Puzzlehash hint,
) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ColdWallet implements Wallet {
});

@override
final EnhancedChiaFullNodeInterface fullNode;
final ChiaFullNodeInterface fullNode;
final WalletKeychain keychain;

@override
Expand Down

0 comments on commit f4c3c9d

Please sign in to comment.