Skip to content

Commit 03c6dd0

Browse files
authored
feat: proc macros
1 parent 08478a3 commit 03c6dd0

File tree

4 files changed

+133
-225
lines changed

4 files changed

+133
-225
lines changed

src/bitcoin.udl

Lines changed: 4 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,9 @@
11
namespace bitcoin {};
22

3-
// ------------------------------------------------------------------------
4-
// Core types
5-
// ------------------------------------------------------------------------
6-
7-
interface Script {
8-
constructor(sequence<u8> raw_output_script);
9-
10-
sequence<u8> to_bytes();
11-
};
12-
13-
interface Amount {
14-
[Name=from_sat]
15-
constructor(u64 from_sat);
16-
17-
[Name=from_btc, Throws=ParseAmountError]
18-
constructor(f64 from_btc);
19-
20-
u64 to_sat();
21-
22-
f64 to_btc();
23-
};
24-
25-
interface FeeRate {
26-
[Name=from_sat_per_vb, Throws=FeeRateError]
27-
constructor(u64 sat_per_vb);
28-
29-
[Name=from_sat_per_kwu]
30-
constructor(u64 sat_per_kwu);
31-
32-
u64 to_sat_per_vb_ceil();
33-
34-
u64 to_sat_per_vb_floor();
35-
36-
u64 to_sat_per_kwu();
37-
};
38-
39-
[Custom]
40-
typedef string Txid;
41-
42-
[Custom]
43-
typedef string BlockHash;
44-
45-
dictionary OutPoint {
46-
Txid txid;
47-
u32 vout;
48-
};
49-
50-
dictionary TxIn {
51-
OutPoint previous_output;
52-
Script script_sig;
53-
u32 sequence;
54-
sequence<sequence<u8>> witness;
55-
};
56-
573
[NonExhaustive]
584
enum Network {
59-
"Bitcoin",
60-
"Testnet",
61-
"Signet",
62-
"Regtest",
63-
};
64-
65-
[Traits=(Display)]
66-
interface Address {
67-
[Throws=AddressParseError]
68-
constructor(string address, Network network);
69-
70-
[Name=from_script, Throws=FromScriptError]
71-
constructor(Script script, Network network);
72-
73-
Script script_pubkey();
74-
75-
string to_qr_uri();
76-
77-
boolean is_valid_for_network(Network network);
78-
};
79-
80-
dictionary TxOut {
81-
Amount value;
82-
Script script_pubkey;
83-
};
84-
85-
interface Transaction {
86-
[Name=deserialize, Throws=EncodeError]
87-
constructor([ByRef] bytes transaction_bytes);
88-
bytes serialize();
89-
string compute_txid();
90-
u64 total_size();
91-
u64 vsize();
92-
boolean is_coinbase();
93-
boolean is_explicitly_rbf();
94-
boolean is_lock_time_enabled();
95-
i32 version();
96-
u64 weight();
97-
sequence<TxIn> input();
98-
sequence<TxOut> output();
99-
u32 lock_time();
100-
};
101-
102-
// ------------------------------------------------------------------------
103-
// Errors
104-
// ------------------------------------------------------------------------
105-
106-
[Error]
107-
enum AddressParseError {
108-
"Base58",
109-
"Bech32",
110-
"WitnessVersion",
111-
"WitnessProgram",
112-
"UnknownHrp",
113-
"LegacyAddressTooLong",
114-
"InvalidBase58PayloadLength",
115-
"InvalidLegacyPrefix",
116-
"NetworkValidation",
117-
"OtherAddressParseErr",
118-
};
119-
120-
[Error]
121-
interface FromScriptError {
122-
UnrecognizedScript();
123-
WitnessProgram(string error_message);
124-
WitnessVersion(string error_message);
125-
OtherFromScriptErr();
126-
};
127-
128-
[Error]
129-
interface ParseAmountError {
130-
OutOfRange();
131-
TooPrecise();
132-
MissingDigits();
133-
InputTooLarge();
134-
InvalidCharacter(string error_message);
135-
OtherParseAmountErr();
136-
};
137-
138-
[Error]
139-
interface FeeRateError {
140-
ArithmeticOverflow();
141-
};
142-
143-
[Error]
144-
interface EncodeError {
145-
Io();
146-
OversizedVectorAllocation();
147-
InvalidChecksum(string expected, string actual);
148-
NonMinimalVarInt();
149-
ParseFailed();
150-
UnsupportedSegwitFlag(u8 flag);
151-
OtherEncodeErr();
5+
"Bitcoin",
6+
"Testnet",
7+
"Signet",
8+
"Regtest",
1529
};

src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bitcoin::amount::ParseAmountError as BitcoinParseAmountError;
44
use bitcoin::consensus::encode::Error as BitcoinEncodeError;
55
use bitcoin::hex::DisplayHex;
66

7-
#[derive(Debug, thiserror::Error)]
7+
#[derive(Debug, thiserror::Error, uniffi::Error)]
88
pub enum AddressParseError {
99
#[error("base58 address encoding error")]
1010
Base58,
@@ -51,13 +51,13 @@ impl From<BitcoinParseError> for AddressParseError {
5151
}
5252
}
5353

54-
#[derive(Debug, thiserror::Error)]
54+
#[derive(Debug, thiserror::Error, uniffi::Error)]
5555
pub enum FeeRateError {
5656
#[error("arithmetic overflow on feerate")]
5757
ArithmeticOverflow,
5858
}
5959

60-
#[derive(Debug, thiserror::Error)]
60+
#[derive(Debug, thiserror::Error, uniffi::Error)]
6161
pub enum FromScriptError {
6262
#[error("script is not a p2pkh, p2sh or witness program")]
6363
UnrecognizedScript,
@@ -88,7 +88,7 @@ impl From<BitcoinFromScriptError> for FromScriptError {
8888
}
8989
}
9090

91-
#[derive(Debug, thiserror::Error)]
91+
#[derive(Debug, thiserror::Error, uniffi::Error)]
9292
pub enum ParseAmountError {
9393
#[error("amount out of range")]
9494
OutOfRange,
@@ -125,7 +125,7 @@ impl From<BitcoinParseAmountError> for ParseAmountError {
125125
}
126126
}
127127

128-
#[derive(Debug, thiserror::Error)]
128+
#[derive(Debug, thiserror::Error, uniffi::Error)]
129129
pub enum EncodeError {
130130
#[error("io error")]
131131
Io,

0 commit comments

Comments
 (0)