[bindings] Support converting Network to rust, update variants
authorMatt Corallo <git@bluematt.me>
Fri, 5 Mar 2021 23:51:23 +0000 (18:51 -0500)
committerMatt Corallo <git@bluematt.me>
Sat, 6 Mar 2021 00:16:29 +0000 (19:16 -0500)
c-bindings-gen/src/types.rs
lightning-c-bindings/src/bitcoin/network.rs

index 7fc7e4cd905cff8d1cc66cd39aba44988b38c535..3e6acaa8d00674139748fa419ef7b4635a6c65f2 100644 (file)
@@ -842,6 +842,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_vec(local_"),
                        "bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
                        "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
+                       "bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
                        "bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"),
                        "bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice::from_slice(&local_"),
 
@@ -899,6 +900,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "bitcoin::blockdata::transaction::Transaction" => Some(")"),
                        "bitcoin::blockdata::transaction::OutPoint" => Some(")"),
                        "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
+                       "bitcoin::network::constants::Network" => Some(")"),
                        "bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""),
                        "bitcoin::blockdata::block::Block" if is_ref => Some(")"),
 
index 13799c0a57c49e913044f6cd3f00d7e892e22bfb..52cb2ce68a26dbdf81cccc50702568a9aa449722 100644 (file)
@@ -5,6 +5,7 @@ pub enum Network {
        Bitcoin,
        Testnet,
        Regtest,
+       Signet,
 }
 
 impl Network {
@@ -13,6 +14,15 @@ impl Network {
                        Network::Bitcoin => BitcoinNetwork::Bitcoin,
                        Network::Testnet => BitcoinNetwork::Testnet,
                        Network::Regtest => BitcoinNetwork::Regtest,
+                       Network::Signet => BitcoinNetwork::Signet,
+               }
+       }
+       pub(crate) fn from_bitcoin(net: BitcoinNetwork) -> Self {
+               match net {
+                       BitcoinNetwork::Bitcoin => Network::Bitcoin,
+                       BitcoinNetwork::Testnet => Network::Testnet,
+                       BitcoinNetwork::Regtest => Network::Regtest,
+                       BitcoinNetwork::Signet => Network::Signet,
                }
        }
 }