|
3 | 3 | //! High level APIs for creating C FFI compatible environment. |
4 | 4 | //! |
5 | 5 |
|
6 | | -use elements::secp256k1_zkp::ffi::CPtr; |
7 | 6 | use hashes::Hash; |
8 | 7 | use std::os::raw::{c_uchar, c_uint}; |
9 | 8 |
|
@@ -36,49 +35,38 @@ fn new_raw_output<'raw>( |
36 | 35 | fn new_raw_input<'raw>( |
37 | 36 | inp: &'raw elements::TxIn, |
38 | 37 | in_utxo: &'raw ElementsUtxo, |
39 | | - inp_data: &c_elements::RawInputData, |
| 38 | + inp_data: &'raw c_elements::RawInputData, |
40 | 39 | ) -> c_elements::CRawInput<'raw> { |
41 | | - unsafe { |
42 | | - let mut raw_input = std::mem::MaybeUninit::<c_elements::CRawInput>::uninit(); |
43 | | - |
44 | | - let (issue_nonce_ptr, issue_entropy_ptr, issue_amt_ptr, issue_infl_key_ptr) = |
45 | | - if inp.has_issuance() { |
46 | | - ( |
47 | | - inp.asset_issuance.asset_blinding_nonce.as_c_ptr(), |
48 | | - inp.asset_issuance.asset_entropy.as_ptr(), |
49 | | - value_ptr(inp.asset_issuance.amount, &inp_data.issuance_amount), |
50 | | - value_ptr( |
51 | | - inp.asset_issuance.inflation_keys, |
52 | | - &inp_data.issuance_inflation_keys, |
53 | | - ), |
54 | | - ) |
55 | | - } else { |
56 | | - ( |
57 | | - std::ptr::null(), |
58 | | - std::ptr::null(), |
59 | | - std::ptr::null(), |
60 | | - std::ptr::null(), |
61 | | - ) |
62 | | - }; |
63 | | - c_elements::c_set_rawInput( |
64 | | - raw_input.as_mut_ptr(), |
65 | | - opt_ptr(annex_ptr(&inp_data.annex).as_ref()), |
66 | | - inp_data.genesis_hash.as_ref(), |
67 | | - &script_ptr(&inp.script_sig), |
68 | | - AsRef::<[u8]>::as_ref(&inp.previous_output.txid).as_ptr(), |
69 | | - inp.previous_output.vout as c_uint, |
70 | | - inp_data.asset.as_ref(), |
71 | | - value_ptr(in_utxo.value, &inp_data.value), |
72 | | - &script_ptr(&in_utxo.script_pubkey), |
73 | | - inp.sequence.0 as c_uint, |
74 | | - issue_nonce_ptr, // FIXME: CHECK ASSET ISSUANCE IS NOT NULL. EASIER WITH NEW ELEMENTS VERSION. |
75 | | - issue_entropy_ptr, |
76 | | - issue_amt_ptr, |
77 | | - issue_infl_key_ptr, |
78 | | - &range_proof_ptr(&inp_data.amount_range_proof), |
79 | | - &range_proof_ptr(&inp_data.inflation_keys_range_proof), |
80 | | - ); |
81 | | - raw_input.assume_init() |
| 40 | + c_elements::CRawInput { |
| 41 | + // FIXME actually pass the annex in; see https://github.com/BlockstreamResearch/simplicity/issues/311 for some difficulty here. |
| 42 | + annex: core::ptr::null(), |
| 43 | + prev_txid: inp.previous_output.txid.as_ref(), |
| 44 | + pegin: inp_data.genesis_hash.as_ref(), |
| 45 | + issuance: if inp.has_issuance() { |
| 46 | + c_elements::CRawInputIssuance { |
| 47 | + blinding_nonce: Some(inp.asset_issuance.asset_blinding_nonce.as_ref()), |
| 48 | + asset_entropy: Some(&inp.asset_issuance.asset_entropy), |
| 49 | + amount: value_ptr(inp.asset_issuance.amount, &inp_data.issuance_amount), |
| 50 | + inflation_keys: value_ptr( |
| 51 | + inp.asset_issuance.inflation_keys, |
| 52 | + &inp_data.issuance_inflation_keys, |
| 53 | + ), |
| 54 | + amount_range_proof: c_elements::CRawBuffer::new(&inp_data.amount_range_proof), |
| 55 | + inflation_keys_range_proof: c_elements::CRawBuffer::new( |
| 56 | + &inp_data.inflation_keys_range_proof, |
| 57 | + ), |
| 58 | + } |
| 59 | + } else { |
| 60 | + c_elements::CRawInputIssuance::no_issuance() |
| 61 | + }, |
| 62 | + txo: c_elements::CRawInputTxo { |
| 63 | + asset: inp_data.asset.as_ref(), |
| 64 | + value: value_ptr(in_utxo.value, &inp_data.value), |
| 65 | + script_pubkey: c_elements::CRawBuffer::new(in_utxo.script_pubkey.as_bytes()), |
| 66 | + }, |
| 67 | + script_sig: c_elements::CRawBuffer::new(inp.script_sig.as_bytes()), |
| 68 | + prev_txout_index: inp.previous_output.vout, |
| 69 | + sequence: inp.sequence.to_consensus_u32(), |
82 | 70 | } |
83 | 71 | } |
84 | 72 |
|
@@ -218,28 +206,6 @@ fn value_ptr(value: confidential::Value, data: &[u8]) -> *const c_uchar { |
218 | 206 | } |
219 | 207 | } |
220 | 208 |
|
221 | | -fn opt_ptr<T>(t: Option<&T>) -> *const T { |
222 | | - if let Some(t) = t { |
223 | | - t |
224 | | - } else { |
225 | | - std::ptr::null() |
226 | | - } |
227 | | -} |
228 | | - |
229 | | -fn script_ptr(script: &elements::Script) -> c_elements::CRawBuffer { |
230 | | - c_elements::CRawBuffer::new(script.as_bytes()) |
231 | | -} |
232 | | - |
233 | | -fn annex_ptr(annex: &Option<Vec<c_uchar>>) -> Option<c_elements::CRawBuffer> { |
234 | | - annex |
235 | | - .as_ref() |
236 | | - .map(|annex| c_elements::CRawBuffer::new(annex)) |
237 | | -} |
238 | | - |
239 | | -fn range_proof_ptr(rangeproof: &[c_uchar]) -> c_elements::CRawBuffer { |
240 | | - c_elements::CRawBuffer::new(rangeproof) |
241 | | -} |
242 | | - |
243 | 209 | fn serialize_rangeproof(rangeproof: &Option<Box<RangeProof>>) -> Vec<c_uchar> { |
244 | 210 | rangeproof |
245 | 211 | .as_ref() |
|
0 commit comments