Skip to content

Commit 859b128

Browse files
committed
Update hard-coded type definitions
1 parent 1b629f5 commit 859b128

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed

c-bindings-gen/src/types.rs

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ fn initial_clonable_types() -> HashSet<String> {
810810
res.insert("crate::c_types::PublicKey".to_owned());
811811
res.insert("crate::c_types::Transaction".to_owned());
812812
res.insert("crate::c_types::Witness".to_owned());
813+
res.insert("crate::c_types::WitnessVersion".to_owned());
813814
res.insert("crate::c_types::TxOut".to_owned());
814815
res.insert("crate::c_types::Signature".to_owned());
815816
res.insert("crate::c_types::RecoverableSignature".to_owned());
@@ -977,6 +978,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
977978
"str" if is_ref => Some("crate::c_types::Str"),
978979
"alloc::string::String"|"String" => Some("crate::c_types::Str"),
979980

981+
"bitcoin::Address" => Some("crate::c_types::Str"),
982+
980983
"std::time::Duration"|"core::time::Duration" => Some("u64"),
981984
"std::time::SystemTime" => Some("u64"),
982985
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some("crate::c_types::IOError"),
@@ -1007,7 +1010,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10071010

10081011
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"),
10091012
"bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
1010-
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
1013+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
10111014
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction"),
10121015
"bitcoin::Witness" => Some("crate::c_types::Witness"),
10131016
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"),
@@ -1016,7 +1019,13 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10161019
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("*const [u8; 80]"),
10171020
"bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice"),
10181021

1019-
"bitcoin::hash_types::PubkeyHash"|"bitcoin::hash_types::WPubkeyHash"|"bitcoin::hash_types::ScriptHash"
1022+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
1023+
"bitcoin::hash_types::WPubkeyHash"|
1024+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
1025+
if !is_ref => Some("crate::c_types::TwentyBytes"),
1026+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
1027+
"bitcoin::hash_types::WPubkeyHash"|
1028+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
10201029
if is_ref => Some("*const [u8; 20]"),
10211030
"bitcoin::hash_types::WScriptHash"
10221031
if is_ref => Some("*const [u8; 32]"),
@@ -1095,6 +1104,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10951104
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(""),
10961105
"bitcoin::secp256k1::SecretKey" if is_ref => Some("&::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *"),
10971106
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(""),
1107+
"bitcoin::secp256k1::Scalar" if is_ref => Some("&"),
10981108
"bitcoin::secp256k1::Scalar" if !is_ref => Some(""),
10991109
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes("),
11001110

@@ -1104,18 +1114,22 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11041114
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(""),
11051115
"bitcoin::Witness" if is_ref => Some("&"),
11061116
"bitcoin::Witness" => Some(""),
1107-
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::C_to_bitcoin_outpoint("),
1117+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::C_to_bitcoin_outpoint("),
11081118
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""),
11091119
"bitcoin::network::constants::Network" => Some(""),
11101120
"bitcoin::util::address::WitnessVersion" => Some(""),
11111121
"bitcoin::blockdata::block::BlockHeader" => Some("&::bitcoin::consensus::encode::deserialize(unsafe { &*"),
11121122
"bitcoin::blockdata::block::Block" if is_ref => Some("&::bitcoin::consensus::encode::deserialize("),
11131123

1114-
"bitcoin::hash_types::PubkeyHash" if is_ref =>
1124+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash" if !is_ref =>
1125+
Some("bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner("),
1126+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash" if is_ref =>
11151127
Some("&bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(unsafe { *"),
11161128
"bitcoin::hash_types::WPubkeyHash" if is_ref =>
11171129
Some("&bitcoin::hash_types::WPubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(unsafe { *"),
1118-
"bitcoin::hash_types::ScriptHash" if is_ref =>
1130+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash" if !is_ref =>
1131+
Some("bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner("),
1132+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash" if is_ref =>
11191133
Some("&bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(unsafe { *"),
11201134
"bitcoin::hash_types::WScriptHash" if is_ref =>
11211135
Some("&bitcoin::hash_types::WScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(unsafe { *"),
@@ -1124,7 +1138,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11241138
"bitcoin::hash_types::Txid" if is_ref => Some("&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*"),
11251139
"bitcoin::hash_types::Txid" if !is_ref => Some("::bitcoin::hash_types::Txid::from_slice(&"),
11261140
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" => Some("::bitcoin::hash_types::BlockHash::from_slice(&"),
1127-
"bitcoin::blockdata::constants::ChainHash" => Some("::bitcoin::blockdata::constants::ChainHash::from_slice(&"),
1141+
"bitcoin::blockdata::constants::ChainHash" => Some("::bitcoin::blockdata::constants::ChainHash::from(&"),
11281142
"lightning::ln::PaymentHash" if !is_ref => Some("::lightning::ln::PaymentHash("),
11291143
"lightning::ln::PaymentHash" if is_ref => Some("&::lightning::ln::PaymentHash(unsafe { *"),
11301144
"lightning::ln::PaymentPreimage" if !is_ref => Some("::lightning::ln::PaymentPreimage("),
@@ -1189,28 +1203,34 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11891203
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(".into_rust()"),
11901204
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(".into_rust()"),
11911205
"bitcoin::secp256k1::SecretKey" if is_ref => Some("}[..]).unwrap()"),
1192-
"bitcoin::secp256k1::Scalar" if !is_ref => Some(".into_rust()"),
1206+
"bitcoin::secp256k1::Scalar" => Some(".into_rust()"),
11931207
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".data)"),
11941208

11951209
"bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"),
11961210
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"),
11971211
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(".into_bitcoin()"),
11981212
"bitcoin::Witness" => Some(".into_bitcoin()"),
1199-
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
1213+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
12001214
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"),
12011215
"bitcoin::network::constants::Network" => Some(".into_bitcoin()"),
12021216
"bitcoin::util::address::WitnessVersion" => Some(".into()"),
12031217
"bitcoin::blockdata::block::BlockHeader" => Some(" }).unwrap()"),
12041218
"bitcoin::blockdata::block::Block" => Some(".to_slice()).unwrap()"),
12051219

1206-
"bitcoin::hash_types::PubkeyHash"|"bitcoin::hash_types::WPubkeyHash"|
1207-
"bitcoin::hash_types::ScriptHash"|"bitcoin::hash_types::WScriptHash"
1220+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
1221+
"bitcoin::hash_types::WPubkeyHash"|"bitcoin::hash_types::WScriptHash"|
1222+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
1223+
if !is_ref => Some(".data))"),
1224+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
1225+
"bitcoin::hash_types::WPubkeyHash"|"bitcoin::hash_types::WScriptHash"|
1226+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
12081227
if is_ref => Some(" }.clone()))"),
12091228

12101229
// Newtypes that we just expose in their original form.
12111230
"bitcoin::hash_types::Txid" if is_ref => Some(" }[..]).unwrap()"),
12121231
"bitcoin::hash_types::Txid" => Some(".data[..]).unwrap()"),
1213-
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash"|"bitcoin::blockdata::constants::ChainHash" if !is_ref => Some(".data[..]).unwrap()"),
1232+
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" if !is_ref => Some(".data[..]).unwrap()"),
1233+
"bitcoin::blockdata::constants::ChainHash" if !is_ref => Some(".data[..])"),
12141234
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
12151235
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
12161236
|"lightning::chain::keysinterface::KeyMaterial"
@@ -1266,6 +1286,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12661286
"str" if is_ref => Some(""),
12671287
"alloc::string::String"|"String" => Some(""),
12681288

1289+
"bitcoin::Address" => Some("alloc::string::ToString::to_string(&"),
1290+
12691291
"std::time::Duration"|"core::time::Duration" => Some(""),
12701292
"std::time::SystemTime" => Some(""),
12711293
"std::io::Error"|"lightning::io::Error" => Some("crate::c_types::IOError::from_rust("),
@@ -1290,7 +1312,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12901312
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature::from_rust(&"),
12911313
"bitcoin::secp256k1::SecretKey" if is_ref => Some(""),
12921314
"bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey::from_rust("),
1293-
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar::from_rust("),
1315+
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar::from_rust(&"),
12941316
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
12951317

12961318
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
@@ -1299,7 +1321,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12991321
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction::from_bitcoin(&"),
13001322
"bitcoin::Witness" if is_ref => Some("crate::c_types::Witness::from_bitcoin("),
13011323
"bitcoin::Witness" if !is_ref => Some("crate::c_types::Witness::from_bitcoin(&"),
1302-
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
1324+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
13031325
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
13041326
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
13051327
"bitcoin::util::address::WitnessVersion" => Some(""),
@@ -1308,6 +1330,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13081330

13091331
"bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13101332

1333+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
1334+
"bitcoin::hash_types::WPubkeyHash"|"bitcoin::hash_types::WScriptHash"|
1335+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
1336+
if !is_ref => Some("crate::c_types::TwentyBytes { data: "),
1337+
13111338
// Newtypes that we just expose in their original form.
13121339
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
13131340
if is_ref => Some(""),
@@ -1353,6 +1380,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13531380
"alloc::string::String"|"String" if is_ref => Some(".as_str().into()"),
13541381
"alloc::string::String"|"String" => Some(".into()"),
13551382

1383+
"bitcoin::Address" => Some(").into()"),
1384+
13561385
"std::time::Duration"|"core::time::Duration" => Some(".as_secs()"),
13571386
"std::time::SystemTime" => Some(".duration_since(::std::time::SystemTime::UNIX_EPOCH).expect(\"Times must be post-1970\").as_secs()"),
13581387
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some(")"),
@@ -1383,7 +1412,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13831412
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"),
13841413
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(")"),
13851414
"bitcoin::Witness" => Some(")"),
1386-
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
1415+
"bitcoin::OutPoint"|"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
13871416
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
13881417
"bitcoin::network::constants::Network" => Some(")"),
13891418
"bitcoin::util::address::WitnessVersion" => Some(".into()"),
@@ -1392,11 +1421,18 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13921421

13931422
"bitcoin::hash_types::Txid" if !is_ref => Some(".into_inner() }"),
13941423

1424+
"bitcoin::PubkeyHash"|"bitcoin::hash_types::PubkeyHash"|
1425+
"bitcoin::hash_types::WPubkeyHash"|"bitcoin::hash_types::WScriptHash"|
1426+
"bitcoin::ScriptHash"|"bitcoin::hash_types::ScriptHash"
1427+
if !is_ref => Some(".as_hash().into_inner() }"),
1428+
13951429
// Newtypes that we just expose in their original form.
1396-
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
1430+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
13971431
if is_ref => Some(".as_inner()"),
1398-
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
1432+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
13991433
if !is_ref => Some(".into_inner() }"),
1434+
"bitcoin::blockdata::constants::ChainHash" if is_ref => Some(".as_bytes() }"),
1435+
"bitcoin::blockdata::constants::ChainHash" if !is_ref => Some(".to_bytes() }"),
14001436
"bitcoin::secp256k1::Message" if !is_ref => Some(".as_ref().clone() }"),
14011437
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
14021438
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"

0 commit comments

Comments
 (0)