Skip to content

Commit f88af9a

Browse files
committed
Update hard-coded types and add some new manual bitcoin types
1 parent 5ed4076 commit f88af9a

File tree

2 files changed

+111
-32
lines changed

2 files changed

+111
-32
lines changed

c-bindings-gen/src/types.rs

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
548548
// Add primitives to the "imports" list:
549549
Self::insert_primitive(&mut imports, "bool");
550550
Self::insert_primitive(&mut imports, "u128");
551+
Self::insert_primitive(&mut imports, "i64");
551552
Self::insert_primitive(&mut imports, "u64");
552553
Self::insert_primitive(&mut imports, "u32");
553554
Self::insert_primitive(&mut imports, "u16");
@@ -814,6 +815,7 @@ fn initial_clonable_types() -> HashSet<String> {
814815
res.insert("crate::c_types::Transaction".to_owned());
815816
res.insert("crate::c_types::Witness".to_owned());
816817
res.insert("crate::c_types::WitnessVersion".to_owned());
818+
res.insert("crate::c_types::TxIn".to_owned());
817819
res.insert("crate::c_types::TxOut".to_owned());
818820
res.insert("crate::c_types::Signature".to_owned());
819821
res.insert("crate::c_types::RecoverableSignature".to_owned());
@@ -948,6 +950,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
948950
pub fn is_primitive(&self, full_path: &str) -> bool {
949951
match full_path {
950952
"bool" => true,
953+
"i64" => true,
951954
"u64" => true,
952955
"u32" => true,
953956
"u16" => true,
@@ -1011,21 +1014,27 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10111014
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature"),
10121015
"bitcoin::secp256k1::SecretKey" if is_ref => Some("*const [u8; 32]"),
10131016
"bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey"),
1017+
"bitcoin::secp256k1::KeyPair" if !is_ref => Some("crate::c_types::SecretKey"),
10141018
"bitcoin::secp256k1::Scalar" if is_ref => Some("*const crate::c_types::BigEndianScalar"),
10151019
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar"),
10161020
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
10171021

1018-
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"),
1019-
"bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
1022+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if is_ref => Some("crate::c_types::u8slice"),
1023+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
10201024
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
10211025
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction"),
10221026
"bitcoin::Witness" => Some("crate::c_types::Witness"),
1023-
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"),
1027+
"bitcoin::TxIn"|"bitcoin::blockdata::transaction::TxIn" if !is_ref => Some("crate::c_types::TxIn"),
1028+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" => Some("crate::c_types::TxOut"),
10241029
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network"),
10251030
"bitcoin::util::address::WitnessVersion" => Some("crate::c_types::WitnessVersion"),
10261031
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("*const [u8; 80]"),
10271032
"bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice"),
10281033

1034+
"bitcoin::PackedLockTime"|"bitcoin::blockdata::locktime::PackedLockTime" => Some("u32"),
1035+
1036+
"bitcoin::psbt::PartiallySignedTransaction" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
1037+
10291038
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
10301039
"bitcoin::hash_types::WPubkeyHash"|
10311040
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
@@ -1045,11 +1054,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10451054
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
10461055
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
10471056
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1048-
|"lightning::chain::keysinterface::KeyMaterial"
1057+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
10491058
if is_ref => Some("*const [u8; 32]"),
10501059
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
10511060
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1052-
|"lightning::chain::keysinterface::KeyMaterial"
1061+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
10531062
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
10541063

10551064
"lightning::io::Read" => Some("crate::c_types::u8slice"),
@@ -1111,23 +1120,29 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11111120
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(""),
11121121
"bitcoin::secp256k1::SecretKey" if is_ref => Some("&::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *"),
11131122
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(""),
1123+
"bitcoin::secp256k1::KeyPair" if !is_ref => Some("::bitcoin::secp256k1::KeyPair::new("),
11141124
"bitcoin::secp256k1::Scalar" if is_ref => Some("&"),
11151125
"bitcoin::secp256k1::Scalar" if !is_ref => Some(""),
11161126
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes("),
11171127

1118-
"bitcoin::blockdata::script::Script" if is_ref => Some("&::bitcoin::blockdata::script::Script::from(Vec::from("),
1119-
"bitcoin::blockdata::script::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("),
1128+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if is_ref => Some("&::bitcoin::blockdata::script::Script::from(Vec::from("),
1129+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("),
11201130
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("&"),
11211131
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(""),
11221132
"bitcoin::Witness" if is_ref => Some("&"),
11231133
"bitcoin::Witness" => Some(""),
11241134
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::C_to_bitcoin_outpoint("),
1135+
"bitcoin::TxIn"|"bitcoin::blockdata::transaction::TxIn" if !is_ref => Some(""),
11251136
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""),
11261137
"bitcoin::network::constants::Network" => Some(""),
11271138
"bitcoin::util::address::WitnessVersion" => Some(""),
11281139
"bitcoin::blockdata::block::BlockHeader" => Some("&::bitcoin::consensus::encode::deserialize(unsafe { &*"),
11291140
"bitcoin::blockdata::block::Block" if is_ref => Some("&::bitcoin::consensus::encode::deserialize("),
11301141

1142+
"bitcoin::PackedLockTime"|"bitcoin::blockdata::locktime::PackedLockTime" => Some("::bitcoin::PackedLockTime("),
1143+
1144+
"bitcoin::psbt::PartiallySignedTransaction" if !is_ref => Some("::bitcoin::consensus::encode::deserialize("),
1145+
11311146
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash" if !is_ref =>
11321147
Some("bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner("),
11331148
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash" if is_ref =>
@@ -1155,8 +1170,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11551170
"lightning::ln::channelmanager::PaymentId" if is_ref=> Some("&::lightning::ln::channelmanager::PaymentId( unsafe { *"),
11561171
"lightning::ln::channelmanager::InterceptId" if !is_ref => Some("::lightning::ln::channelmanager::InterceptId("),
11571172
"lightning::ln::channelmanager::InterceptId" if is_ref=> Some("&::lightning::ln::channelmanager::InterceptId( unsafe { *"),
1158-
"lightning::chain::keysinterface::KeyMaterial" if !is_ref => Some("::lightning::chain::keysinterface::KeyMaterial("),
1159-
"lightning::chain::keysinterface::KeyMaterial" if is_ref=> Some("&::lightning::chain::keysinterface::KeyMaterial( unsafe { *"),
1173+
"lightning::sign::KeyMaterial" if !is_ref => Some("::lightning::sign::KeyMaterial("),
1174+
"lightning::sign::KeyMaterial" if is_ref=> Some("&::lightning::sign::KeyMaterial( unsafe { *"),
1175+
"lightning::chain::ClaimId" if !is_ref => Some("::lightning::chain::ClaimId("),
1176+
"lightning::chain::ClaimId" if is_ref=> Some("&::lightning::chain::ClaimId( unsafe { *"),
11601177

11611178
// List of traits we map (possibly during processing of other files):
11621179
"lightning::io::Read" => Some("&mut "),
@@ -1210,20 +1227,26 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12101227
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(".into_rust()"),
12111228
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(".into_rust()"),
12121229
"bitcoin::secp256k1::SecretKey" if is_ref => Some("}[..]).unwrap()"),
1230+
"bitcoin::secp256k1::KeyPair" if !is_ref => Some(".into_rust())"),
12131231
"bitcoin::secp256k1::Scalar" => Some(".into_rust()"),
12141232
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".data)"),
12151233

1216-
"bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"),
1217-
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"),
1234+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if is_ref => Some(".to_slice()))"),
1235+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if !is_ref => Some(".into_rust())"),
12181236
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(".into_bitcoin()"),
12191237
"bitcoin::Witness" => Some(".into_bitcoin()"),
12201238
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
1239+
"bitcoin::TxIn"|"bitcoin::blockdata::transaction::TxIn" if !is_ref => Some(".into_rust()"),
12211240
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"),
12221241
"bitcoin::network::constants::Network" => Some(".into_bitcoin()"),
12231242
"bitcoin::util::address::WitnessVersion" => Some(".into()"),
12241243
"bitcoin::blockdata::block::BlockHeader" => Some(" }).unwrap()"),
12251244
"bitcoin::blockdata::block::Block" => Some(".to_slice()).unwrap()"),
12261245

1246+
"bitcoin::PackedLockTime"|"bitcoin::blockdata::locktime::PackedLockTime" => Some(")"),
1247+
1248+
"bitcoin::psbt::PartiallySignedTransaction" if !is_ref => Some(".as_slice()).expect(\"Invalid PSBT format\")"),
1249+
12271250
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
12281251
"bitcoin::hash_types::WPubkeyHash"|"bitcoin::hash_types::WScriptHash"|
12291252
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
@@ -1240,11 +1263,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12401263
"bitcoin::blockdata::constants::ChainHash" if !is_ref => Some(".data[..])"),
12411264
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
12421265
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1243-
|"lightning::chain::keysinterface::KeyMaterial"
1266+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
12441267
if !is_ref => Some(".data)"),
12451268
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
12461269
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1247-
|"lightning::chain::keysinterface::KeyMaterial"
1270+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
12481271
if is_ref => Some(" })"),
12491272

12501273
// List of traits we map (possibly during processing of other files):
@@ -1319,22 +1342,30 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13191342
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature::from_rust(&"),
13201343
"bitcoin::secp256k1::SecretKey" if is_ref => Some(""),
13211344
"bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey::from_rust("),
1345+
"bitcoin::secp256k1::KeyPair" if !is_ref => Some("crate::c_types::SecretKey::from_rust("),
13221346
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar::from_rust(&"),
13231347
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13241348

1325-
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
1326-
"bitcoin::blockdata::script::Script" if !is_ref => Some(""),
1349+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
1350+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if !is_ref => Some(""),
13271351
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("crate::c_types::Transaction::from_bitcoin("),
13281352
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction::from_bitcoin(&"),
13291353
"bitcoin::Witness" if is_ref => Some("crate::c_types::Witness::from_bitcoin("),
13301354
"bitcoin::Witness" if !is_ref => Some("crate::c_types::Witness::from_bitcoin(&"),
1331-
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
1332-
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
1355+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" if is_ref => Some("crate::c_types::bitcoin_to_C_outpoint("),
1356+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" if !is_ref => Some("crate::c_types::bitcoin_to_C_outpoint(&"),
1357+
"bitcoin::TxIn"|"bitcoin::blockdata::transaction::TxIn" if !is_ref => Some("crate::c_types::TxIn::from_rust(&"),
1358+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust(&"),
1359+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if is_ref => Some("crate::c_types::TxOut::from_rust("),
13331360
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
13341361
"bitcoin::util::address::WitnessVersion" => Some(""),
13351362
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"),
13361363
"bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice::from_slice(&local_"),
13371364

1365+
"bitcoin::PackedLockTime"|"bitcoin::blockdata::locktime::PackedLockTime" => Some(""),
1366+
1367+
"bitcoin::psbt::PartiallySignedTransaction" if !is_ref => Some("::bitcoin::consensus::encode::serialize(&"),
1368+
13381369
"bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13391370

13401371
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
@@ -1350,11 +1381,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13501381
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13511382
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
13521383
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1353-
|"lightning::chain::keysinterface::KeyMaterial"
1384+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
13541385
if is_ref => Some("&"),
13551386
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
13561387
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1357-
|"lightning::chain::keysinterface::KeyMaterial"
1388+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
13581389
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13591390

13601391
"lightning::io::Read" => Some("crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec("),
@@ -1412,20 +1443,26 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14121443
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(")"),
14131444
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(")"),
14141445
"bitcoin::secp256k1::SecretKey" if is_ref => Some(".as_ref()"),
1446+
"bitcoin::secp256k1::KeyPair" if !is_ref => Some(".secret_key())"),
14151447
"bitcoin::secp256k1::Scalar" if !is_ref => Some(")"),
14161448
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".secret_bytes() }"),
14171449

1418-
"bitcoin::blockdata::script::Script" if is_ref => Some("[..])"),
1419-
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"),
1450+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if is_ref => Some("[..])"),
1451+
"bitcoin::blockdata::script::Script"|"bitcoin::Script" if !is_ref => Some(".into_bytes().into()"),
14201452
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(")"),
14211453
"bitcoin::Witness" => Some(")"),
14221454
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
1423-
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
1455+
"bitcoin::TxIn"|"bitcoin::blockdata::transaction::TxIn" if !is_ref => Some(")"),
1456+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" => Some(")"),
14241457
"bitcoin::network::constants::Network" => Some(")"),
14251458
"bitcoin::util::address::WitnessVersion" => Some(".into()"),
14261459
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""),
14271460
"bitcoin::blockdata::block::Block" if is_ref => Some(")"),
14281461

1462+
"bitcoin::PackedLockTime"|"bitcoin::blockdata::locktime::PackedLockTime" => Some(".0"),
1463+
1464+
"bitcoin::psbt::PartiallySignedTransaction" if !is_ref => Some(").into()"),
1465+
14291466
"bitcoin::hash_types::Txid" if !is_ref => Some(".into_inner() }"),
14301467

14311468
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
@@ -1443,11 +1480,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14431480
"bitcoin::secp256k1::Message" if !is_ref => Some(".as_ref().clone() }"),
14441481
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
14451482
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1446-
|"lightning::chain::keysinterface::KeyMaterial"
1483+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
14471484
if is_ref => Some(".0"),
14481485
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
14491486
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
1450-
|"lightning::chain::keysinterface::KeyMaterial"
1487+
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
14511488
if !is_ref => Some(".0 }"),
14521489

14531490
"lightning::io::Read" => Some("))"),

0 commit comments

Comments
 (0)