From 2b1ba14db5d31ad15cc255f3a4b64a3a5bf16638 Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Tue, 1 Sep 2020 14:01:20 +0100 Subject: [PATCH] grin output_identifier refactoring --- impls/src/test_framework/mod.rs | 5 +++-- libwallet/src/internal/tx.rs | 2 +- libwallet/src/slate.rs | 16 +++++----------- libwallet/src/slate_versions/v4.rs | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/impls/src/test_framework/mod.rs b/impls/src/test_framework/mod.rs index b08964cec..4dd921b24 100644 --- a/impls/src/test_framework/mod.rs +++ b/impls/src/test_framework/mod.rs @@ -40,9 +40,10 @@ fn get_output_local(chain: &chain::Chain, commit: pedersen::Commitment) -> Optio if chain.get_unspent(commit).unwrap().is_some() { let block_height = chain.get_header_for_output(commit).unwrap().height; let output_pos = chain.get_output_pos(&commit).unwrap_or(0); - return Some(api::Output::new(&commit, block_height, output_pos)); + Some(api::Output::new(&commit, block_height, output_pos)) + } else { + None } - None } /// Get a kernel from the chain locally diff --git a/libwallet/src/internal/tx.rs b/libwallet/src/internal/tx.rs index ba3a64dca..f4c1f6451 100644 --- a/libwallet/src/internal/tx.rs +++ b/libwallet/src/internal/tx.rs @@ -616,7 +616,7 @@ mod test { .unwrap(); let inputs: Vec = tx2.inputs().into(); - assert_eq!(tx1.outputs()[0].features, inputs[0].features); + assert_eq!(tx1.outputs()[0].features(), inputs[0].features); assert_eq!(tx1.outputs()[0].commitment(), inputs[0].commitment()); } diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index e8cc3b7c9..222748f28 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -839,8 +839,8 @@ impl From<&Slate> for Option> { } for o in outs.iter() { ret_vec.push(CommitsV4 { - f: o.features.into(), - c: o.commit, + f: o.features().into(), + c: o.commitment(), p: Some(o.proof), }); } @@ -1020,14 +1020,8 @@ pub fn tx_from_slate_v4(slate: &SlateV4) -> Option { let mut tx = Transaction::empty().with_kernel(kernel); for c in coms.iter() { - match &c.p { - Some(p) => { - tx = tx.with_output(Output { - features: c.f.into(), - commit: c.c, - proof: p.clone(), - }) - } + match c.p { + Some(p) => tx = tx.with_output(Output::new(c.f.into(), c.c, p)), None => { tx = tx.with_input(Input { features: c.f.into(), @@ -1036,7 +1030,7 @@ pub fn tx_from_slate_v4(slate: &SlateV4) -> Option { } } } - tx.offset = slate.off.clone(); + tx = tx.with_offset(slate.off.clone()); Some(tx) } diff --git a/libwallet/src/slate_versions/v4.rs b/libwallet/src/slate_versions/v4.rs index 2564547de..bfcffc937 100644 --- a/libwallet/src/slate_versions/v4.rs +++ b/libwallet/src/slate_versions/v4.rs @@ -316,8 +316,8 @@ impl From<&Output> for CbOutputV4 { fn from(output: &Output) -> CbOutputV4 { CbOutputV4 { features: CbOutputFeatures::Coinbase, - commit: output.commit, - proof: output.proof, + commit: output.commitment(), + proof: output.proof(), } } }