Compare commits
No commits in common. "d78c269d96fe7d8a626cf701b8051c40f251e232" and "c4799c3558175dd2b5bdb80e618cb3143e1c41b6" have entirely different histories.
d78c269d96
...
c4799c3558
6 changed files with 56 additions and 56 deletions
|
@ -9,8 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `makeZcashCall` function moved into this library
|
|
||||||
- `RpcResponse`, `RpcCall` types moved into this library
|
|
||||||
- Functions to decode Sapling transactions
|
- Functions to decode Sapling transactions
|
||||||
- Tests for Sapling decoding
|
- Tests for Sapling decoding
|
||||||
- Type for block response
|
- Type for block response
|
||||||
|
|
|
@ -349,7 +349,7 @@ pub extern "C" fn rust_wrapper_ufvk_decode(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_wrapper_sapling_note_decrypt_v2(
|
pub extern "C" fn rust_wrapper_sapling_note_decrypt(
|
||||||
key: *const u8,
|
key: *const u8,
|
||||||
key_len: usize,
|
key_len: usize,
|
||||||
note: *const u8,
|
note: *const u8,
|
||||||
|
@ -364,10 +364,12 @@ pub extern "C" fn rust_wrapper_sapling_note_decrypt_v2(
|
||||||
match svk {
|
match svk {
|
||||||
Ok(k) => {
|
Ok(k) => {
|
||||||
let domain = SaplingDomain::for_height(MainNetwork, BlockHeight::from_u32(2000000));
|
let domain = SaplingDomain::for_height(MainNetwork, BlockHeight::from_u32(2000000));
|
||||||
let action2 = OutputDescription::read(&mut note_reader).unwrap();
|
let action2: Transaction = Transaction::read(&mut note_reader, Nu5).unwrap();
|
||||||
|
let bundle = action2.sapling_bundle().unwrap();
|
||||||
|
let sh_out = bundle.shielded_outputs();
|
||||||
let fvk = k.to_diversifiable_full_viewing_key().to_ivk(SaplingScope::External);
|
let fvk = k.to_diversifiable_full_viewing_key().to_ivk(SaplingScope::External);
|
||||||
let pivk = SaplingPreparedIncomingViewingKey::new(&fvk);
|
let pivk = SaplingPreparedIncomingViewingKey::new(&fvk);
|
||||||
let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &action2);
|
let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &sh_out[0]);
|
||||||
match result {
|
match result {
|
||||||
Some((n, r, m)) => {
|
Some((n, r, m)) => {
|
||||||
let hn = Hnote {note: n.value().inner(), recipient: r.to_bytes().to_vec(), memo: m.as_slice().to_vec() };
|
let hn = Hnote {note: n.value().inner(), recipient: r.to_bytes().to_vec(), memo: m.as_slice().to_vec() };
|
||||||
|
@ -445,15 +447,41 @@ pub extern "C" fn rust_wrapper_tx_parse(
|
||||||
let parsed_tx = Transaction::read(&mut tx_reader, Nu5);
|
let parsed_tx = Transaction::read(&mut tx_reader, Nu5);
|
||||||
match parsed_tx {
|
match parsed_tx {
|
||||||
Ok(t) => {
|
Ok(t) => {
|
||||||
let s_bundle = t.sapling_bundle().unwrap().shielded_outputs();
|
let s_bundle = t.sapling_bundle();
|
||||||
let mut s_output = Vec::new();
|
let o_bundle = t.orchard_bundle();
|
||||||
for s_each_out in s_bundle.iter() {
|
match s_bundle {
|
||||||
let mut out_bytes = Vec::new();
|
Some(sb) => {
|
||||||
let _ = s_each_out.write_v4(&mut out_bytes);
|
let s_o = true;
|
||||||
s_output.push(out_bytes);
|
match o_bundle {
|
||||||
|
Some(ob) => {
|
||||||
|
let o_a = true;
|
||||||
|
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
||||||
|
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
let o_a = false;
|
||||||
|
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
||||||
|
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
let s_o = false;
|
||||||
|
match o_bundle {
|
||||||
|
Some(ob) => {
|
||||||
|
let o_a = true;
|
||||||
|
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
||||||
|
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
let o_a = false;
|
||||||
|
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
||||||
|
marshall_to_haskell_var(&x, out, out_len, RW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
marshall_to_haskell_var(&s_output, out, out_len, RW);
|
|
||||||
//TODO: write array of bytes
|
|
||||||
|
|
||||||
},
|
},
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
|
|
|
@ -72,7 +72,7 @@ import ZcashHaskell.Types
|
||||||
-> `Bool'
|
-> `Bool'
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_sapling_note_decrypt_v2 as rustWrapperSaplingNoteDecode
|
{# fun unsafe rust_wrapper_sapling_note_decrypt as rustWrapperSaplingNoteDecode
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, toBorshVar* `BS.ByteString'&
|
, toBorshVar* `BS.ByteString'&
|
||||||
, getVarBuffer `Buffer DecodedNote'&
|
, getVarBuffer `Buffer DecodedNote'&
|
||||||
|
@ -95,9 +95,3 @@ import ZcashHaskell.Types
|
||||||
-> `()'
|
-> `()'
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_tx_parse as rustWrapperTxParse
|
|
||||||
{ toBorshVar* `BS.ByteString'&
|
|
||||||
, getVarBuffer `Buffer [BS.ByteString]'&
|
|
||||||
}
|
|
||||||
-> `()'
|
|
||||||
#}
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
|
|
||||||
module ZcashHaskell.Sapling where
|
module ZcashHaskell.Sapling where
|
||||||
|
|
||||||
import C.Zcash
|
import C.Zcash
|
||||||
|
@ -7,25 +5,15 @@ import C.Zcash
|
||||||
, rustWrapperSaplingCheck
|
, rustWrapperSaplingCheck
|
||||||
, rustWrapperSaplingNoteDecode
|
, rustWrapperSaplingNoteDecode
|
||||||
, rustWrapperSaplingVkDecode
|
, rustWrapperSaplingVkDecode
|
||||||
, rustWrapperTxParse
|
|
||||||
)
|
)
|
||||||
import Data.Aeson
|
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
||||||
import ZcashHaskell.Types
|
import ZcashHaskell.Types (DecodedNote(..), ShieldedOutput(..))
|
||||||
( DecodedNote(..)
|
|
||||||
, RawTxResponse(..)
|
|
||||||
, ShieldedOutput(..)
|
|
||||||
, decodeHexText
|
|
||||||
)
|
|
||||||
|
|
||||||
-- | Check if given bytesting is a valid encoded shielded address
|
-- | Check if given bytesting is a valid encoded shielded address
|
||||||
isValidShieldedAddress :: BS.ByteString -> Bool
|
isValidShieldedAddress :: BS.ByteString -> Bool
|
||||||
isValidShieldedAddress = rustWrapperIsShielded
|
isValidShieldedAddress = rustWrapperIsShielded
|
||||||
|
|
||||||
getShieldedOutputs :: BS.ByteString -> [BS.ByteString]
|
|
||||||
getShieldedOutputs t = withPureBorshVarBuffer $ rustWrapperTxParse t
|
|
||||||
|
|
||||||
-- | Check if given bytestring is a valid Sapling viewing key
|
-- | Check if given bytestring is a valid Sapling viewing key
|
||||||
isValidSaplingViewingKey :: BS.ByteString -> Bool
|
isValidSaplingViewingKey :: BS.ByteString -> Bool
|
||||||
isValidSaplingViewingKey = rustWrapperSaplingVkDecode
|
isValidSaplingViewingKey = rustWrapperSaplingVkDecode
|
||||||
|
@ -43,17 +31,3 @@ decodeSaplingOutput key out =
|
||||||
where
|
where
|
||||||
decodedAction =
|
decodedAction =
|
||||||
withPureBorshVarBuffer $ rustWrapperSaplingNoteDecode key out
|
withPureBorshVarBuffer $ rustWrapperSaplingNoteDecode key out
|
||||||
|
|
||||||
instance FromJSON RawTxResponse where
|
|
||||||
parseJSON =
|
|
||||||
withObject "RawTxResponse" $ \obj -> do
|
|
||||||
i <- obj .: "txid"
|
|
||||||
o <- obj .: "orchard"
|
|
||||||
h <- obj .: "hex"
|
|
||||||
a <- o .: "actions"
|
|
||||||
pure $
|
|
||||||
RawTxResponse
|
|
||||||
i
|
|
||||||
(decodeHexText h)
|
|
||||||
(getShieldedOutputs (decodeHexText h))
|
|
||||||
a
|
|
||||||
|
|
|
@ -103,10 +103,20 @@ instance FromJSON BlockResponse where
|
||||||
data RawTxResponse = RawTxResponse
|
data RawTxResponse = RawTxResponse
|
||||||
{ rt_id :: T.Text
|
{ rt_id :: T.Text
|
||||||
, rt_hex :: BS.ByteString
|
, rt_hex :: BS.ByteString
|
||||||
, rt_shieldedOutputs :: [BS.ByteString]
|
, rt_shieldedOutputs :: [ShieldedOutput]
|
||||||
, rt_orchardActions :: [OrchardAction]
|
, rt_orchardActions :: [OrchardAction]
|
||||||
} deriving (Prelude.Show, Eq)
|
} deriving (Prelude.Show, Eq)
|
||||||
|
|
||||||
|
instance FromJSON RawTxResponse where
|
||||||
|
parseJSON =
|
||||||
|
withObject "RawTxResponse" $ \obj -> do
|
||||||
|
i <- obj .: "txid"
|
||||||
|
s <- obj .: "vShieldedOutput"
|
||||||
|
o <- obj .: "orchard"
|
||||||
|
h <- obj .: "hex"
|
||||||
|
a <- o .: "actions"
|
||||||
|
pure $ RawTxResponse i (decodeHexText h) s a
|
||||||
|
|
||||||
-- * Sapling
|
-- * Sapling
|
||||||
-- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@.
|
-- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@.
|
||||||
data ShieldedOutput = ShieldedOutput
|
data ShieldedOutput = ShieldedOutput
|
||||||
|
|
12
test/Spec.hs
12
test/Spec.hs
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue