Skip to content

Commit

Permalink
[WIP] Fix error with slate serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
GeneFerneau committed Jul 7, 2021
1 parent 3584a61 commit a71105b
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 69 deletions.
24 changes: 14 additions & 10 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 @@ -256,7 +257,7 @@ pub trait ForeignRpc {
}
],
"sta": "A2",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -285,7 +286,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 @@ -355,7 +356,7 @@ pub trait ForeignRpc {
}
],
"sta": "I3",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand All @@ -378,7 +379,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 All @@ -387,6 +388,7 @@ where
dest_acct_name: Option<String>,
dest: Option<String>,
) -> Result<VersionedSlate, ErrorKind> {
let v = in_slate.version();
let slate_from = Slate::from(in_slate);
let out_slate = Foreign::receive_tx(
self,
Expand All @@ -395,7 +397,7 @@ where
dest,
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, out_slate.version()).map_err(|e| e.kind())?)
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}

fn receive_atomic_tx(
Expand All @@ -404,6 +406,7 @@ where
dest_acct_name: Option<String>,
dest: Option<String>,
) -> Result<VersionedSlate, ErrorKind> {
let v = in_slate.version();
let slate_from = Slate::from(in_slate);
let out_slate = Foreign::receive_atomic_tx(
self,
Expand All @@ -412,13 +415,14 @@ where
dest,
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate).map_err(|e| e.kind())?)
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}

fn finalize_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
let v = in_slate.version();
let out_slate =
Foreign::finalize_tx(self, &Slate::from(in_slate), true).map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, out_slate.version()).map_err(|e| e.kind())?)
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}
}

Expand Down
64 changes: 36 additions & 28 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::core::global;
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::{
AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult,
OutputCommitMapping, PaymentProof, Slate, Slatepack, SlatepackAddress, StatusMessage, TxFlow,
TxLogEntry, VersionedSlate, WalletInfo, WalletLCProvider,
OutputCommitMapping, PaymentProof, Slate, SlateVersion, Slatepack, SlatepackAddress,
StatusMessage, TxFlow, TxLogEntry, VersionedSlate, WalletInfo, WalletLCProvider,
};
use crate::util::logger::LoggingConfig;
use crate::util::secp::key::{PublicKey, SecretKey};
Expand Down 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 @@ -635,7 +635,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 @@ -714,7 +714,7 @@ pub trait OwnerRpc {
}
],
"sta": "A1",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand All @@ -738,7 +738,7 @@ pub trait OwnerRpc {
"params": {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"slate": {
"ver": "4:2",
"ver": "5:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "A2",
"off": "a5a632f26f27a9b71e98c1c8b8098bb41204ffcfd206d995f9c16d10764ad95a",
Expand Down Expand Up @@ -807,7 +807,7 @@ pub trait OwnerRpc {
}
],
"sta": "A3",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -836,7 +836,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 @@ -898,7 +898,7 @@ pub trait OwnerRpc {
}
],
"sta": "S3",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand All @@ -922,7 +922,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 @@ -1050,7 +1050,7 @@ pub trait OwnerRpc {
"id": "0436430c-2b02-624c-2032-570501212b00",
"sigs": [],
"sta": "S3",
"ver": "4:3"
"ver": "5:3"
}
}
}
Expand Down Expand Up @@ -1689,7 +1689,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 @@ -1712,7 +1712,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 @@ -1766,7 +1766,7 @@ pub trait OwnerRpc {
}
],
"sta": "S1",
"ver": "4:2"
"ver": "5:2"
}
}
}
Expand Down Expand Up @@ -2021,7 +2021,8 @@ 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())?;
Ok(VersionedSlate::into_version(slate, slate.version()).map_err(|e| e.kind())?)
let v = slate.version();
Ok(VersionedSlate::into_version(slate, v).map_err(|e| e.kind())?)
}

fn issue_invoice_tx(
Expand All @@ -2031,7 +2032,8 @@ where
) -> Result<VersionedSlate, ErrorKind> {
let slate = Owner::issue_invoice_tx(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(slate, slate.version()).map_err(|e| e.kind())?)
let v = slate.version();
Ok(VersionedSlate::into_version(slate, v).map_err(|e| e.kind())?)
}

fn process_invoice_tx(
Expand All @@ -2047,7 +2049,8 @@ where
args,
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, out_slate.version()).map_err(|e| e.kind())?)
let v = out_slate.version();
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}

fn process_multisig_tx(
Expand All @@ -2061,7 +2064,7 @@ where
&Slate::from(in_slate),
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate).map_err(|e| e.kind())?)
Ok(VersionedSlate::into_version(out_slate, SlateVersion::V5).map_err(|e| e.kind())?)
}

fn init_atomic_swap(
Expand All @@ -2071,7 +2074,8 @@ where
) -> Result<VersionedSlate, ErrorKind> {
let out_slate = Owner::init_atomic_swap(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate).map_err(|e| e.kind())?)
let v = out_slate.version();
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}

fn countersign_atomic_swap(
Expand All @@ -2084,7 +2088,8 @@ where
let out_slate =
Owner::countersign_atomic_swap(self, &slate, (&token.keychain_mask).as_ref(), r_addr)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate).map_err(|e| e.kind())?)
let v = out_slate.version();
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}

fn finalize_tx(
Expand All @@ -2098,7 +2103,8 @@ where
&Slate::from(in_slate),
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate).map_err(|e| e.kind())?)
let v = out_slate.version();
Ok(VersionedSlate::into_version(out_slate, v).map_err(|e| e.kind())?)
}

fn tx_lock_outputs(&self, token: Token, in_slate: VersionedSlate) -> Result<(), ErrorKind> {
Expand Down Expand Up @@ -2134,9 +2140,10 @@ where
)
.map_err(|e| e.kind())?;
match out_slate {
Some(s) => Ok(Some(
VersionedSlate::into_version(s, s.version()).map_err(|e| e.kind())?,
)),
Some(s) => Ok({
let v = s.version();
Some(VersionedSlate::into_version(s, v).map_err(|e| e.kind())?)
}),
None => Ok(None),
}
}
Expand Down Expand Up @@ -2337,7 +2344,8 @@ where
secret_indices,
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(slate, slate.version()).map_err(|e| e.kind())?)
let v = slate.version();
Ok(VersionedSlate::into_version(slate, v).map_err(|e| e.kind())?)
}

fn decode_slatepack_message(
Expand Down
6 changes: 1 addition & 5 deletions api/tests/slate_versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ fn receive_tx(vs: VersionedSlate) -> VersionedSlate {
)
.unwrap();
let (call, tracker) = bound_method.call();
<<<<<<< HEAD
let json_response = run_doctest_foreign(call.as_request(), dir, true, 5, false, false)
=======
let json_response = run_doctest_foreign(call.as_request(), dir, 5, TxFlow::Standard)
>>>>>>> 6535bda (Add atomic swap owner/foreign RPC functions)
let json_response = run_doctest_foreign(call.as_request(), dir, 5, TxFlow::Standard, false)
.unwrap()
.unwrap();
let mut response = easy_jsonrpc_mw::Response::from_json_response(json_response).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion impls/src/adapters/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl SlatePutter for PathToSlate {
}*/
let mut pub_tx = File::create(&self.0)?;
// TODO:
let out_slate = VersionedSlate::into_version(slate.clone())?;
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
Loading

0 comments on commit a71105b

Please sign in to comment.