Skip to content

Commit d29a3e6

Browse files
committed
refactor(kyoto): switch to proc macros
1 parent d154117 commit d29a3e6

File tree

4 files changed

+101
-239
lines changed

4 files changed

+101
-239
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,6 @@ interface TxidParseError {
330330
InvalidTxid(string txid);
331331
};
332332

333-
/// Errors that may occur building a light client.
334-
[Error]
335-
interface LightClientBuilderError {
336-
/// A database could not be opened or created.
337-
DatabaseError(string reason);
338-
};
339-
340-
/// Errors that may occur sending messages to a node.
341-
[Error]
342-
enum LightClientError {
343-
/// The node is not currently running.
344-
"NodeStopped",
345-
};
346-
347333
// ------------------------------------------------------------------------
348334
// bdk_wallet crate - types module
349335
// ------------------------------------------------------------------------
@@ -1318,206 +1304,6 @@ interface AddressData {
13181304
// bdk-kyoto crate
13191305
// ------------------------------------------------------------------------
13201306

1321-
/// Build a BIP 157/158 light client to fetch transactions for a `Wallet`.
1322-
///
1323-
/// Options:
1324-
/// * List of `Peer`: Bitcoin full-nodes for the light client to connect to. May be empty.
1325-
/// * `connections`: The number of connections for the light client to maintain.
1326-
/// * `scan_type`: Sync, recover, or start a new wallet. For more information see [`ScanType`].
1327-
/// * `data_dir`: Optional directory to store block headers and peers.
1328-
///
1329-
/// A note on recovering wallets. Developers should allow users to provide an
1330-
/// approximate recovery height and an estimated number of transactions for the
1331-
/// wallet. When determining how many scripts to check filters for, the `Wallet`
1332-
/// `lookahead` value will be used. To ensure all transactions are recovered, the
1333-
/// `lookahead` should be roughly the number of transactions in the wallet history.
1334-
interface LightClientBuilder {
1335-
/// Start a new [`LightClientBuilder`]
1336-
constructor();
1337-
1338-
/// The number of connections for the light client to maintain. Default is two.
1339-
LightClientBuilder connections(u8 connections);
1340-
1341-
/// Directory to store block headers and peers. If none is provided, the current
1342-
/// working directory will be used.
1343-
LightClientBuilder data_dir(string data_dir);
1344-
1345-
/// Select between syncing, recovering, or scanning for new wallets.
1346-
LightClientBuilder scan_type(ScanType scan_type);
1347-
1348-
/// Bitcoin full-nodes to attempt a connection with.
1349-
LightClientBuilder peers(sequence<Peer> peers);
1350-
1351-
/// Construct a [`LightClient`] for a [`Wallet`].
1352-
[Throws=LightClientBuilderError]
1353-
LightClient build([ByRef] Wallet wallet);
1354-
};
1355-
1356-
/// A [`Client`] handles wallet updates from a [`LightNode`].
1357-
interface Client {
1358-
/// Return the next available log message from a node. If none is returned, the node has stopped.
1359-
[Async, Throws=LightClientError]
1360-
Log next_log();
1361-
1362-
/// Return the next available warning message from a node. If none is returned, the node has stopped.
1363-
[Async, Throws=LightClientError]
1364-
Warning next_warning();
1365-
1366-
/// Return an [`Update`]. This is method returns once the node syncs to the rest of
1367-
/// the network or a new block has been gossiped.
1368-
[Async]
1369-
Update? update();
1370-
1371-
/// Add scripts for the node to watch for as they are revealed. Typically used after creating
1372-
/// a transaction or revealing a receive address.
1373-
///
1374-
/// Note that only future blocks will be checked for these scripts, not past blocks.
1375-
[Async, Throws=LightClientError]
1376-
void add_revealed_scripts([ByRef] Wallet wallet);
1377-
1378-
/// The minimum fee rate required to broadcast a transcation to all connected peers.
1379-
[Async, Throws=LightClientError]
1380-
FeeRate min_broadcast_feerate();
1381-
1382-
/// Broadcast a transaction to the network, erroring if the node has stopped running.
1383-
[Async, Throws=LightClientError]
1384-
void broadcast([ByRef] Transaction transaction);
1385-
1386-
/// Check if the node is still running in the background.
1387-
[Async]
1388-
boolean is_running();
1389-
1390-
/// Stop the [`LightNode`]. Errors if the node is already stopped.
1391-
[Async, Throws=LightClientError]
1392-
void shutdown();
1393-
};
1394-
1395-
/// A [`LightNode`] gathers transactions for a [`Wallet`].
1396-
/// To receive [`Update`] for [`Wallet`], refer to the
1397-
/// [`Client`]. The [`LightNode`] will run until instructed
1398-
/// to stop.
1399-
interface LightNode {
1400-
/// Start the node on a detached OS thread and immediately return.
1401-
void run();
1402-
};
1403-
1404-
/// Receive a [`Client`] and [`LightNode`].
1405-
dictionary LightClient {
1406-
/// Publish events to the node, like broadcasting transactions or adding scripts.
1407-
Client client;
1408-
1409-
/// The node to run and fetch transactions for a [`Wallet`].
1410-
LightNode node;
1411-
};
1412-
1413-
/// Sync a wallet from the last known block hash, recover a wallet from a specified height,
1414-
/// or perform an expedited block header download for a new wallet.
1415-
[Enum]
1416-
interface ScanType {
1417-
/// Perform an expedited header and filter download for a new wallet.
1418-
/// If this option is not set, and the wallet has no history, the
1419-
/// entire chain will be scanned for script inclusions.
1420-
New();
1421-
1422-
/// Sync an existing wallet from the last stored chain checkpoint.
1423-
Sync();
1424-
1425-
/// Recover an existing wallet by scanning from the specified height.
1426-
Recovery(u32 from_height);
1427-
};
1428-
1429-
/// A peer to connect to over the Bitcoin peer-to-peer network.
1430-
dictionary Peer {
1431-
/// The IP address to reach the node.
1432-
IpAddress address;
1433-
1434-
/// The port to reach the node. If none is provided, the default
1435-
/// port for the selected network will be used.
1436-
u16? port;
1437-
1438-
/// Does the remote node offer encrypted peer-to-peer connection.
1439-
boolean v2_transport;
1440-
};
1441-
1442-
/// An IP address to connect to over TCP.
1443-
interface IpAddress {
1444-
/// Build an IPv4 address.
1445-
[Name=from_ipv4]
1446-
constructor(u8 q1, u8 q2, u8 q3, u8 q4);
1447-
1448-
/// Build an IPv6 address.
1449-
[Name=from_ipv6]
1450-
constructor(u16 a, u16 b, u16 c, u16 d, u16 e, u16 f, u16 g, u16 h);
1451-
};
1452-
1453-
/// A log message from the node.
1454-
[Enum]
1455-
interface Log {
1456-
/// A human-readable debug message.
1457-
Debug(string log);
1458-
1459-
/// All the required connections have been met. This is subject to change.
1460-
ConnectionsMet();
1461-
1462-
/// A percentage value of filters that have been scanned.
1463-
Progress(f32 progress);
1464-
1465-
/// A state in the node syncing process.
1466-
StateUpdate(NodeState node_state);
1467-
1468-
/// A transaction was broadcast over the wire.
1469-
/// The transaction may or may not be rejected by recipient nodes.
1470-
TxSent(string txid);
1471-
};
1472-
1473-
/// Warnings a node may issue while running.
1474-
[Enum]
1475-
interface Warning {
1476-
/// The node is looking for connections to peers.
1477-
NeedConnections();
1478-
1479-
/// A connection to a peer timed out.
1480-
PeerTimedOut();
1481-
1482-
/// The node was unable to connect to a peer in the database.
1483-
CouldNotConnect();
1484-
1485-
/// A connection was maintained, but the peer does not signal for compact block filers.
1486-
NoCompactFilters();
1487-
1488-
/// The node has been waiting for new inv and will find new peers to avoid block withholding.
1489-
PotentialStaleTip();
1490-
1491-
/// A peer sent us a peer-to-peer message the node did not request.
1492-
UnsolicitedMessage();
1493-
1494-
/// The provided starting height is deeper than the database history.
1495-
/// This should not occur under normal use.
1496-
InvalidStartHeight();
1497-
1498-
/// The headers in the database do not link together.
1499-
/// Recoverable by deleting the database.
1500-
CorruptedHeaders();
1501-
1502-
/// A transaction got rejected, likely for being an insufficient fee or non-standard transaction.
1503-
TransactionRejected(string txid, string? reason);
1504-
1505-
/// A database failed to persist some data and may retry again.
1506-
FailedPersistence(string warning);
1507-
1508-
/// The peer sent us a potential fork.
1509-
EvaluatingFork();
1510-
1511-
/// The peer database has no values.
1512-
EmptyPeerDatabase();
1513-
1514-
/// An unexpected error occured processing a peer-to-peer message.
1515-
UnexpectedSyncError(string warning);
1516-
1517-
/// The node failed to respond to a message sent from the client.
1518-
RequestFailed();
1519-
};
1520-
15211307
/// The state of the node with respect to connected peers.
15221308
[Remote]
15231309
enum NodeState {

bdk-ffi/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,13 @@ pub enum TxidParseError {
782782
InvalidTxid { txid: String },
783783
}
784784

785-
#[derive(Debug, thiserror::Error)]
785+
#[derive(Debug, thiserror::Error, uniffi::Error)]
786786
pub enum LightClientBuilderError {
787787
#[error("the database could not be opened or created: {reason}")]
788788
DatabaseError { reason: String },
789789
}
790790

791-
#[derive(Debug, thiserror::Error)]
791+
#[derive(Debug, thiserror::Error, uniffi::Error)]
792792
pub enum LightClientError {
793793
#[error("the node is no longer running")]
794794
NodeStopped,

0 commit comments

Comments
 (0)