Skip to content

Commit

Permalink
Added docs. Updated rust project name to not colllide with lwk depend…
Browse files Browse the repository at this point in the history
…ency. Updated generated code
  • Loading branch information
i5hi committed Jan 10, 2025
1 parent 1fd3601 commit dedabaa
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 80 deletions.
2 changes: 2 additions & 0 deletions lib/src/generated/api/descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import 'types.dart';

// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `fmt`

/// Wallet descriptor class used to create a new wallet
class Descriptor {
final String ctDescriptor;

const Descriptor({
required this.ctDescriptor,
});

/// Createa new wpkh confidential descriptor based on Slip77 blinding key derivation
static Future<Descriptor> newConfidential(
{required Network network, required String mnemonic}) =>
LwkCore.instance.api.crateApiDescriptorDescriptorNewConfidential(
Expand Down
7 changes: 7 additions & 0 deletions lib/src/generated/api/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ part 'types.freezed.dart';
// These types are ignored because they are not used by any `pub` functions: `AssetIdBTreeMapInt`, `AssetIdBTreeMapUInt`, `AssetIdHashMapInt`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `into`

/// Address class which contains both standard and confidential addresses with the address index in the wallet
@freezed
class Address with _$Address {
const Address._();
Expand All @@ -20,18 +21,22 @@ class Address with _$Address {
required String confidential,
required int index,
}) = _Address;

/// Create an address from a scriptpubkey. Always returns 0 as the index is only for wallet generated addresses
static Future<Address> addressFromScript(
{required Network network,
required String script,
required String blindingKey}) =>
LwkCore.instance.api.crateApiTypesAddressAddressFromScript(
network: network, script: script, blindingKey: blindingKey);

/// Validate the address string and return the network
static Future<Network> validate({required String addressString}) =>
LwkCore.instance.api
.crateApiTypesAddressValidate(addressString: addressString);
}

/// Balance represents a balance of a specific asset
@freezed
class Balance with _$Balance {
const factory Balance({
Expand Down Expand Up @@ -69,6 +74,7 @@ class OutPoint with _$OutPoint {
}) = _OutPoint;
}

/// Decoded PSET amounts
class PsetAmounts {
final BigInt absoluteFees;
final List<Balance> balances;
Expand All @@ -90,6 +96,7 @@ class PsetAmounts {
balances == other.balances;
}

/// Transaction object returned by getTransactions.
@freezed
class Tx with _$Tx {
const factory Tx({
Expand Down
16 changes: 16 additions & 0 deletions lib/src/generated/api/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,43 @@ import 'types.dart';
// Rust type: RustOpaqueNom<Mutex < lwk_wollet :: Wollet >>
abstract class MutexWollet implements RustOpaqueInterface {}

/// Main wallet object
class Wallet {
final MutexWollet inner;

const Wallet({
required this.inner,
});

/// Get an address from a specific index
Future<Address> address({required int index}) => LwkCore.instance.api
.crateApiWalletWalletAddress(that: this, index: index);

/// Get the last unused address from the wallet
Future<Address> addressLastUnused() =>
LwkCore.instance.api.crateApiWalletWalletAddressLastUnused(
that: this,
);

/// Get balances for a wallet.
Future<List<Balance>> balances() =>
LwkCore.instance.api.crateApiWalletWalletBalances(
that: this,
);

/// Get the blinding key string for the wallet
Future<String> blindingKey() =>
LwkCore.instance.api.crateApiWalletWalletBlindingKey(
that: this,
);

/// Broadcast a signed transaction
static Future<String> broadcastTx(
{required String electrumUrl, required List<int> txBytes}) =>
LwkCore.instance.api.crateApiWalletWalletBroadcastTx(
electrumUrl: electrumUrl, txBytes: txBytes);

/// Build a transaction for a specific asset
Future<String> buildAssetTx(
{required BigInt sats,
required String outAddress,
Expand All @@ -56,6 +63,7 @@ class Wallet {
feeRate: feeRate,
asset: asset);

/// Build a LBTC transaction
Future<String> buildLbtcTx(
{required BigInt sats,
required String outAddress,
Expand All @@ -68,44 +76,52 @@ class Wallet {
feeRate: feeRate,
drain: drain);

/// Decode a transaction given a PSET
Future<PsetAmounts> decodeTx({required String pset}) =>
LwkCore.instance.api.crateApiWalletWalletDecodeTx(that: this, pset: pset);

/// Get the descriptor string for the wallet
Future<String> descriptor() =>
LwkCore.instance.api.crateApiWalletWalletDescriptor(
that: this,
);

/// Initializes a wallet from a specific db path and descriptor
static Future<Wallet> init(
{required Network network,
required String dbpath,
required Descriptor descriptor}) =>
LwkCore.instance.api.crateApiWalletWalletInit(
network: network, dbpath: dbpath, descriptor: descriptor);

/// Sign a wallet transaction (pset)
Future<Uint8List> signTx(
{required Network network,
required String pset,
required String mnemonic}) =>
LwkCore.instance.api.crateApiWalletWalletSignTx(
that: this, network: network, pset: pset, mnemonic: mnemonic);

/// Sign a pset with extra details (used for asset transactions)
Future<String> signedPsetWithExtraDetails(
{required Network network,
required String pset,
required String mnemonic}) =>
LwkCore.instance.api.crateApiWalletWalletSignedPsetWithExtraDetails(
that: this, network: network, pset: pset, mnemonic: mnemonic);

/// Syncs the wallet db with its latest state fetched from the electrum server
Future<void> sync(
{required String electrumUrl, required bool validateDomain}) =>
LwkCore.instance.api.crateApiWalletWalletSync(
that: this, electrumUrl: electrumUrl, validateDomain: validateDomain);

/// Get the transaction history of the wallet
Future<List<Tx>> txs() => LwkCore.instance.api.crateApiWalletWalletTxs(
that: this,
);

/// Get utxos of the wallet
Future<List<TxOut>> utxos() => LwkCore.instance.api.crateApiWalletWalletUtxos(
that: this,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/generated/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LwkCore extends BaseEntrypoint<LwkCoreApi, LwkCoreApiImpl, LwkCoreWire> {

static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
stem: 'lwk',
stem: 'lwk_dart',
ioDirectory: 'rust/target/release/',
webPrefix: 'pkg/',
);
Expand Down Expand Up @@ -709,7 +709,7 @@ class LwkCoreApiImpl extends LwkCoreApiImplPlatform implements LwkCoreApi {
Blockchain dco_decode_blockchain(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.isNotEmpty)
if (arr.length != 0)
throw Exception('unexpected arr length: expect 0 but see ${arr.length}');
return Blockchain();
}
Expand Down
Loading

0 comments on commit dedabaa

Please sign in to comment.