Skip to content

Commit

Permalink
[WIP] Fix Slatepack deserialization for V5
Browse files Browse the repository at this point in the history
  • Loading branch information
GeneFerneau committed Jun 11, 2021
1 parent f16a1fb commit 113aabb
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 228 deletions.
15 changes: 8 additions & 7 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub trait ForeignRpc {
"Ok": {
"foreign_api_version": 2,
"supported_slate_versions": [
"V5",
"V4"
]
}
Expand Down Expand Up @@ -142,7 +143,7 @@ pub trait ForeignRpc {
}
],
"sta": "S1",
"ver": "4:2"
"ver": "5:2"
},
null,
null
Expand Down Expand Up @@ -177,7 +178,7 @@ pub trait ForeignRpc {
}
],
"sta": "S2",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -218,7 +219,7 @@ pub trait ForeignRpc {
}
],
"sta": "A1",
"ver": "4:2"
"ver": "5:2"
},
null,
null
Expand Down Expand Up @@ -255,7 +256,7 @@ pub trait ForeignRpc {
}
],
"sta": "A2",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -284,7 +285,7 @@ pub trait ForeignRpc {
"method": "finalize_tx",
"id": 1,
"params": [{
"ver": "4:2",
"ver": "5:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "I2",
"off": "383bc9df0dd332629520a0a72f8dd7f0e97d579dccb4dbdc8592aa3d424c846c",
Expand Down Expand Up @@ -354,7 +355,7 @@ pub trait ForeignRpc {
}
],
"sta": "I3",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand All @@ -377,7 +378,7 @@ where

fn build_coinbase(&self, block_fees: &BlockFees) -> Result<VersionedCoinbase, ErrorKind> {
let cb: CbData = Foreign::build_coinbase(self, block_fees).map_err(|e| e.kind())?;
Ok(VersionedCoinbase::into_version(cb, SlateVersion::V4))
Ok(VersionedCoinbase::into_version(cb, SlateVersion::V5))
}

fn receive_tx(
Expand Down
68 changes: 46 additions & 22 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ pub trait OwnerRpc {
}
],
"sta": "S1",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ pub trait OwnerRpc {
}
],
"sta": "I1",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -490,7 +490,7 @@ pub trait OwnerRpc {
}
],
"sta": "I1",
"ver": "4:2"
"ver": "5:2"
},
"args": {
"src_acct_name": null,
Expand Down Expand Up @@ -536,7 +536,7 @@ pub trait OwnerRpc {
}
],
"sta": "I2",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -565,7 +565,7 @@ pub trait OwnerRpc {
"params": {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"slate": {
"ver": "4:2",
"ver": "5:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "S1",
"off": "d202964900000000d302964900000000d402964900000000d502964900000000",
Expand Down Expand Up @@ -642,7 +642,7 @@ pub trait OwnerRpc {
}
],
"sta": "A1",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand All @@ -666,7 +666,7 @@ pub trait OwnerRpc {
"params": {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"slate": {
"ver": "4:2",
"ver": "5:3",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "A2",
"off": "a5a632f26f27a9b71e98c1c8b8098bb41204ffcfd206d995f9c16d10764ad95a",
Expand Down Expand Up @@ -735,7 +735,7 @@ pub trait OwnerRpc {
}
],
"sta": "A3",
"ver": "4:2"
"ver": "5:3"
}
}
}
Expand Down Expand Up @@ -764,7 +764,7 @@ pub trait OwnerRpc {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"slate":
{
"ver": "4:2",
"ver": "5:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "S2",
"off": "6c6a69136154775488782121887bb3c32787a8320551fdb9732ec2d333fe54ee",
Expand Down Expand Up @@ -826,7 +826,7 @@ pub trait OwnerRpc {
}
],
"sta": "S3",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand All @@ -850,7 +850,7 @@ pub trait OwnerRpc {
"params": {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"slate": {
"ver": "4:2",
"ver": "5:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "S3",
"off": "750dbf4fd43b7f4cfd68d2698a522f3ff6e6a00ad9895b33f1ec46493b837b49",
Expand Down Expand Up @@ -978,7 +978,7 @@ pub trait OwnerRpc {
"id": "0436430c-2b02-624c-2032-570501212b00",
"sigs": [],
"sta": "S3",
"ver": "4:3"
"ver": "5:3"
}
}
}
Expand Down Expand Up @@ -1617,7 +1617,7 @@ pub trait OwnerRpc {
"sender_index": 0,
"recipients": [],
"slate": {
"ver": "4:2",
"ver": "5:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "S1",
"off": "d202964900000000d302964900000000d402964900000000d502964900000000",
Expand All @@ -1640,7 +1640,7 @@ pub trait OwnerRpc {
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": "BEGINSLATEPACK. xyfzdULuUuM5r3R kS68aywyCuYssPs Jf1JbvnBcK6NDDo ajiGAgh2SPx4t49 xtKuJE3BZCcSEue ksecMmbSoV2DQbX gGcmJniP9UadcmR N1KSc5FBhwAaUjy LXeYDP7EV7Cmsj4 pLaJdZTJTQbccUH 2zG8QTgoEiEWP5V T6rKst1TibmDAFm RRVHYDtskdYJb5G krqfpgN7RjvPfpm Z5ZFyz6ipAt5q9T 2HCjrTxkHdVi9js 22tr2Lx6iXT5vm8 JL6HhjwyFrSaEmN AjsBE8jgiaAABA6 GGZKwcXeXToMfRt nL9DeX1. ENDSLATEPACK."
"Ok": "BEGINSLATEPACK. 3mz5n34kmt5bXXV ubrnwhufnUc3MHD Jp7ZvuMJTTD96ru 7R1T3SpbmENmkvt 1Tazq77CBGmyNAY RxLCCi7TtGigAtY 7CbhdhNhLpNFK2J 82WoGtDPGPc7ciq TkEiRoopr1hVh1p JKqy9mwHb3HHcHR Znz1QDxBbULjmfU rcQcbuXkGzFEg4i m5xGnvYPt8HMTm8 d3kSe7hSX5929N3 xcdAFBVMYm5GUgd PWvW7QUP5frB4aP zazzB7P1w89x7Jg GmLiX3wBzt4bqJD 83sqrJR5BW8x4NB rvRqsXRDScQTqZd CacQSv7y. ENDSLATEPACK."
}
}
# "#
Expand Down Expand Up @@ -1949,7 +1949,10 @@ where
fn init_send_tx(&self, token: Token, args: InitTxArgs) -> Result<VersionedSlate, ErrorKind> {
let slate = Owner::init_send_tx(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(slate, version).map_err(|e| e.kind())?)
}

Expand All @@ -1960,7 +1963,10 @@ where
) -> Result<VersionedSlate, ErrorKind> {
let slate = Owner::issue_invoice_tx(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(slate, version).map_err(|e| e.kind())?)
}

Expand All @@ -1977,7 +1983,10 @@ where
args,
)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match out_slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}

Expand All @@ -1988,7 +1997,10 @@ where
) -> Result<VersionedSlate, ErrorKind> {
let out_slate = Owner::init_atomic_swap(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match out_slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}

Expand All @@ -2002,7 +2014,10 @@ where
let out_slate =
Owner::countersign_atomic_swap(self, &slate, (&token.keychain_mask).as_ref(), r_addr)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match out_slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}

Expand All @@ -2017,7 +2032,10 @@ where
&Slate::from(in_slate),
)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match out_slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}

Expand Down Expand Up @@ -2055,7 +2073,10 @@ where
.map_err(|e| e.kind())?;
match out_slate {
Some(s) => {
let version = SlateVersion::V4;
let version = match s.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(Some(
VersionedSlate::into_version(s, version).map_err(|e| e.kind())?,
))
Expand Down Expand Up @@ -2260,7 +2281,10 @@ where
secret_indices,
)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
let version = match slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
Ok(VersionedSlate::into_version(slate, version).map_err(|e| e.kind())?)
}

Expand Down
6 changes: 5 additions & 1 deletion impls/src/adapters/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ impl SlatePutter for PathToSlate {
raw_slate.sync_all()?;
}*/
let mut pub_tx = File::create(&self.0)?;
let slate_version = match slate.version_info.version {
4 => SlateVersion::V4,
5 | _ => SlateVersion::V5,
};
// TODO:
let out_slate = VersionedSlate::into_version(slate.clone(), SlateVersion::V4)?;
let out_slate = VersionedSlate::into_version(slate.clone(), slate_version)?;
if as_bin {
let bin_slate =
VersionedBinSlate::try_from(out_slate).map_err(|_| ErrorKind::SlateSer)?;
Expand Down
4 changes: 4 additions & 0 deletions impls/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ impl HttpSlateSender {
return Err(ErrorKind::ClientCallback(report).into());
}

if supported_slate_versions.contains(&"V5".to_owned()) {
return Ok(SlateVersion::V5);
}

if supported_slate_versions.contains(&"V4".to_owned()) {
return Ok(SlateVersion::V4);
}
Expand Down
4 changes: 2 additions & 2 deletions libwallet/src/api_impl/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ where
let keychain = w.keychain(keychain_mask)?;

let is_height_lock = ret_slate.kernel_features == 2;
// derive atomic nonce from the slate's `atomic_id`
// derive atomic secret from the slate's `atomic_id`
let (atomic_id, atomic_secret) = {
let atomic_id = w.next_atomic_id(keychain_mask)?;
let atomic =
Expand All @@ -186,7 +186,7 @@ where
let pub_atomic = PublicKey::from_secret_key(keychain.secp(), &atomic)?;

debug!(
"Your public atomic nonce: {}",
"Your atomic public key: {}",
pub_atomic
.serialize_vec(keychain.secp(), true)
.as_ref()
Expand Down
4 changes: 0 additions & 4 deletions libwallet/src/api_impl/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,6 @@ where
args.ttl_blocks,
)?;

if let Some(v) = args.target_slate_version {
slate.version_info.version = v;
};

let height = w.w2n_client().get_chain_tip()?.0;
let keychain = w.keychain(keychain_mask)?;

Expand Down
2 changes: 1 addition & 1 deletion libwallet/src/internal/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ where
parent_key_id.clone(),
use_test_rng,
is_initiator,
true, /* is_multisig */
false, /* is_multisig */
)?;

context.sec_atomic = atomic_secret;
Expand Down
12 changes: 10 additions & 2 deletions libwallet/src/slate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,16 @@ impl Serialize for Slate {
where
S: Serializer,
{
let v5 = SlateV5::from(self);
v5.serialize(serializer)
match self.version_info.version {
4 => {
let v4 = SlateV4::from(self);
v4.serialize(serializer)
}
5 | _ => {
let v5 = SlateV5::from(self);
v5.serialize(serializer)
}
}
}
}
// Current slate version to versioned conversions
Expand Down
Loading

0 comments on commit 113aabb

Please sign in to comment.