Compare commits
No commits in common. "3203c7e8ffefcb788caf5801425af344a85922bc" and "5a08c802854eebd1b5b4d8e7e1e2dad574b06100" have entirely different histories.
3203c7e8ff
...
5a08c80285
4 changed files with 28 additions and 124 deletions
|
@ -1369,31 +1369,6 @@ pub extern "C" fn rust_wrapper_bech32_encode(
|
|||
marshall_to_haskell_var(&string, out, out_len, RW);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_wrapper_read_sapling_frontier(
|
||||
tree: *const u8,
|
||||
tree_len: usize,
|
||||
out: *mut u8,
|
||||
out_len: &mut usize
|
||||
){
|
||||
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW);
|
||||
let tree_reader = Cursor::new(tree_in);
|
||||
let comm_tree: CommitmentTree<Node, SAPLING_DEPTH> = read_commitment_tree(tree_reader).unwrap();
|
||||
//let comm_tree: Frontier<MerkleHashOrchard, 32> = read_frontier_v1(tree_reader).unwrap();
|
||||
let frontier: Frontier<Node, SAPLING_DEPTH> = comm_tree.to_frontier();
|
||||
match frontier.value() {
|
||||
Some(f1) => {
|
||||
let (pos, leaf, omm) = f1.clone().into_parts();
|
||||
let f = Hfrontier { position: <u64>::from(pos), leaf: Hhex { bytes: leaf.to_bytes().to_vec()}, ommers: omm.iter().map(|&x| x.to_bytes().to_vec()).collect()};
|
||||
marshall_to_haskell_var(&f, out, out_len, RW);
|
||||
},
|
||||
None => {
|
||||
let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![vec![0]]};
|
||||
marshall_to_haskell_var(&f0, out, out_len, RW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_wrapper_read_sapling_commitment_tree(
|
||||
tree: *const u8,
|
||||
|
@ -1712,31 +1687,21 @@ pub extern "C" fn rust_wrapper_create_transaction(
|
|||
build: bool,
|
||||
out: *mut u8,
|
||||
out_len: &mut usize){
|
||||
//let sap_wit_in: Vec<u8> = marshall_from_haskell_var(sap_wit, sap_wit_len, RW);
|
||||
//let sap_wit_reader = Cursor::new(sap_wit_in);
|
||||
//let sap_iw = read_commitment_tree::<Node, Cursor<Vec<u8>>, SAPLING_DEPTH>(sap_wit_reader);
|
||||
let sap_input: Vec<HsaplingInput> = marshall_from_haskell_var(s_input, s_input_len, RW);
|
||||
let sap_anchor =
|
||||
if sap_input.is_empty() {
|
||||
let sap_wit_in: Vec<u8> = marshall_from_haskell_var(sap_wit, sap_wit_len, RW);
|
||||
let sap_wit_reader = Cursor::new(sap_wit_in);
|
||||
let sap_iw = read_commitment_tree::<Node, Cursor<Vec<u8>>, SAPLING_DEPTH>(sap_wit_reader);
|
||||
let sap_anchor = match sap_iw {
|
||||
Ok(s_iw) => {
|
||||
Some(SaplingAnchor::from(s_iw.root()))
|
||||
},
|
||||
Err(_e) => {
|
||||
None
|
||||
} else {
|
||||
let si = &sap_input[0];
|
||||
let swit_reader = Cursor::new(&si.iw);
|
||||
let iw: IncrementalWitness<Node, SAPLING_DEPTH> = read_incremental_witness(swit_reader).unwrap();
|
||||
Some(SaplingAnchor::from(iw.root()))
|
||||
};
|
||||
//let sap_anchor = match sap_iw {
|
||||
//Ok(s_iw) => {
|
||||
//Some(SaplingAnchor::from(s_iw.root()))
|
||||
//},
|
||||
//Err(_e) => {
|
||||
//None
|
||||
//}
|
||||
//};
|
||||
}
|
||||
};
|
||||
//println!("{:?}", sap_anchor);
|
||||
//let orch_wit_in: Vec<u8> = marshall_from_haskell_var(orch_wit, orch_wit_len, RW);
|
||||
//let orch_wit_reader = Cursor::new(orch_wit_in);
|
||||
//let orch_iw = read_commitment_tree::<MerkleHashOrchard, Cursor<Vec<u8>>, 32>(orch_wit_reader);
|
||||
let orch_wit_in: Vec<u8> = marshall_from_haskell_var(orch_wit, orch_wit_len, RW);
|
||||
let orch_wit_reader = Cursor::new(orch_wit_in);
|
||||
let orch_iw = read_commitment_tree::<MerkleHashOrchard, Cursor<Vec<u8>>, 32>(orch_wit_reader);
|
||||
let orch_input: Vec<HorchardInput> = marshall_from_haskell_var(o_input, o_input_len, RW);
|
||||
//let orch_anchor = match orch_iw {
|
||||
//Ok(o_iw) => {
|
||||
|
@ -1781,6 +1746,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
|
|||
}
|
||||
}
|
||||
}
|
||||
let sap_input: Vec<HsaplingInput> = marshall_from_haskell_var(s_input, s_input_len, RW);
|
||||
for s_in in sap_input {
|
||||
if s_in.sk.len() > 1 {
|
||||
let sp_key = ExtendedSpendingKey::from_bytes(&s_in.sk);
|
||||
|
@ -1797,32 +1763,13 @@ pub extern "C" fn rust_wrapper_create_transaction(
|
|||
let iw: IncrementalWitness<Node, SAPLING_DEPTH> = read_incremental_witness(wit_reader).unwrap();
|
||||
let merkle_path = iw.path().unwrap();
|
||||
if net {
|
||||
let mb = main_builder.add_sapling_spend::<String>(&sk, note, merkle_path);
|
||||
match mb {
|
||||
Ok(()) => {
|
||||
continue;
|
||||
},
|
||||
Err(_e) => {
|
||||
let x = Hhex {bytes: vec![5]};
|
||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||
}
|
||||
}
|
||||
let _mb = main_builder.add_sapling_spend::<String>(&sk, note, merkle_path).unwrap();
|
||||
} else {
|
||||
let tb = test_builder.add_sapling_spend::<String>(&sk, note, merkle_path);
|
||||
match tb {
|
||||
Ok(()) => {
|
||||
continue;
|
||||
},
|
||||
Err(_e) => {
|
||||
let x = Hhex {bytes: vec![5]};
|
||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||
}
|
||||
}
|
||||
let _tb = test_builder.add_sapling_spend::<String>(&sk, note, merkle_path).unwrap();
|
||||
}
|
||||
},
|
||||
Err(_e) => {
|
||||
let x = Hhex {bytes: vec![5]};
|
||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1839,27 +1786,9 @@ pub extern "C" fn rust_wrapper_create_transaction(
|
|||
let iw: IncrementalWitness<MerkleHashOrchard, 32> = read_incremental_witness(wit_reader).unwrap();
|
||||
let merkle_path = OrchardMerklePath::from(iw.path().unwrap());
|
||||
if net {
|
||||
let mb = main_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path);
|
||||
match mb {
|
||||
Ok(()) => {
|
||||
continue;
|
||||
},
|
||||
Err(_e) => {
|
||||
let x = Hhex {bytes: vec![7]};
|
||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||
}
|
||||
}
|
||||
let _mb = main_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path).unwrap();
|
||||
} else {
|
||||
let tb = test_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path);
|
||||
match tb {
|
||||
Ok(()) => {
|
||||
continue;
|
||||
},
|
||||
Err(_e) => {
|
||||
let x = Hhex {bytes: vec![7]};
|
||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||
}
|
||||
}
|
||||
let _tb = test_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,9 +204,9 @@ import ZcashHaskell.Types
|
|||
#}
|
||||
|
||||
{# fun unsafe rust_wrapper_read_sapling_commitment_tree as rustWrapperReadSaplingCommitmentTree
|
||||
{ toBorshVar* `SaplingFrontier'&
|
||||
{ toBorshVar* `BS.ByteString'&
|
||||
, toBorshVar* `BS.ByteString'&
|
||||
, getVarBuffer `Buffer SaplingFrontier'&
|
||||
, getVarBuffer `Buffer HexString'&
|
||||
}
|
||||
-> `()'
|
||||
#}
|
||||
|
@ -232,13 +232,6 @@ import ZcashHaskell.Types
|
|||
-> `()'
|
||||
#}
|
||||
|
||||
{# fun unsafe rust_wrapper_read_sapling_frontier as rustWrapperReadSaplingFrontier
|
||||
{ toBorshVar* `BS.ByteString'&
|
||||
, getVarBuffer `Buffer SaplingFrontier'&
|
||||
}
|
||||
-> `()'
|
||||
#}
|
||||
|
||||
{# fun unsafe rust_wrapper_decode_sapling_address as rustWrapperDecodeSaplingAddress
|
||||
{ toBorshVar* `BS.ByteString'&
|
||||
, getVarBuffer `Buffer (BS.ByteString)'&
|
||||
|
|
|
@ -21,7 +21,6 @@ import C.Zcash
|
|||
( rustWrapperDecodeSaplingAddress
|
||||
, rustWrapperIsShielded
|
||||
, rustWrapperReadSaplingCommitmentTree
|
||||
, rustWrapperReadSaplingFrontier
|
||||
, rustWrapperReadSaplingPosition
|
||||
, rustWrapperReadSaplingWitness
|
||||
, rustWrapperSaplingCheck
|
||||
|
@ -185,29 +184,21 @@ genSaplingInternalAddress sk =
|
|||
res =
|
||||
withPureBorshVarBuffer (rustWrapperSaplingChgPaymentAddress $ getBytes sk)
|
||||
|
||||
getSaplingFrontier :: SaplingCommitmentTree -> Maybe SaplingFrontier
|
||||
getSaplingFrontier tree =
|
||||
if sf_pos updatedTree > 1
|
||||
then Just updatedTree
|
||||
else Nothing
|
||||
where
|
||||
updatedTree =
|
||||
withPureBorshVarBuffer $
|
||||
rustWrapperReadSaplingFrontier $ toBytes $ sapTree tree
|
||||
|
||||
-- | Update a Sapling commitment tree
|
||||
updateSaplingCommitmentTree ::
|
||||
SaplingFrontier -- ^ the base tree
|
||||
SaplingCommitmentTree -- ^ the base tree
|
||||
-> HexString -- ^ the new note commitment
|
||||
-> Maybe SaplingFrontier
|
||||
-> Maybe SaplingCommitmentTree
|
||||
updateSaplingCommitmentTree tree cmu =
|
||||
if sf_pos updatedTree > 1
|
||||
then Just updatedTree
|
||||
if BS.length (hexBytes updatedTree) > 1
|
||||
then Just $ SaplingCommitmentTree updatedTree
|
||||
else Nothing
|
||||
where
|
||||
updatedTree =
|
||||
withPureBorshVarBuffer $
|
||||
rustWrapperReadSaplingCommitmentTree tree (hexBytes cmu)
|
||||
rustWrapperReadSaplingCommitmentTree
|
||||
(hexBytes $ sapTree tree)
|
||||
(hexBytes cmu)
|
||||
|
||||
-- | Get the Sapling incremental witness from a commitment tree
|
||||
getSaplingWitness :: SaplingCommitmentTree -> Maybe SaplingWitness
|
||||
|
|
|
@ -611,15 +611,6 @@ newtype SaplingCommitmentTree = SaplingCommitmentTree
|
|||
{ sapTree :: HexString
|
||||
} deriving (Eq, Prelude.Show, Read)
|
||||
|
||||
data SaplingFrontier = SaplingFrontier
|
||||
{ sf_pos :: !Int64
|
||||
, sf_leaf :: !HexString
|
||||
, sf_ommers :: ![BS.ByteString]
|
||||
} deriving stock (Eq, Prelude.Show, GHC.Generic)
|
||||
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
|
||||
deriving anyclass (Data.Structured.Show)
|
||||
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct SaplingFrontier
|
||||
|
||||
-- | Type for a Sapling incremental witness
|
||||
newtype SaplingWitness = SaplingWitness
|
||||
{ sapWit :: HexString
|
||||
|
|
Loading…
Reference in a new issue