mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-03 12:24:27 +01:00
Contracts: wire up the contract view command
contract view was in the CLI help but the command returned Not implemented, and there was no owner API entry point for the existing libwallet implementation. Add owner::contract_view through to the CLI and the owner RPC, with a display for the result. The slate is taken from --input or prompted for, as receive does. is_executed was hardcoded to false. Derive it from our own tx log entry for the slate, which is confirmed once the contract has executed.
This commit is contained in:
@@ -1814,6 +1814,42 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ContractViewArgs {
|
||||
/// Slatepack file to read the contract from
|
||||
pub input_file: Option<String>,
|
||||
/// Slatepack message to read the contract from
|
||||
pub input_slatepack_message: Option<String>,
|
||||
}
|
||||
|
||||
pub fn contract_view<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
args: ContractViewArgs,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K>,
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let (slate, _) = parse_slatepack(
|
||||
owner_api,
|
||||
keychain_mask,
|
||||
args.input_file,
|
||||
args.input_slatepack_message,
|
||||
)?;
|
||||
|
||||
let wallet_inst = owner_api.wallet_inst.clone();
|
||||
let config_path = owner_api.config_path();
|
||||
controller::owner_single_use(wallet_inst, keychain_mask, config_path, |api, m| {
|
||||
let view = api.contract_view(m, &slate)?;
|
||||
display::contract_view(&slate, &view);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ContractRevokeArgs {
|
||||
/// Id of a transaction we want to cancel
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
use crate::core::core::FeeFields;
|
||||
use crate::core::core::{self, amount_to_hr_string};
|
||||
use crate::core::global;
|
||||
use crate::libwallet::contract::types::ContractView;
|
||||
use crate::libwallet::{
|
||||
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, TxLogEntry, ViewWallet, WalletInfo,
|
||||
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, Slate, TxLogEntry, ViewWallet,
|
||||
WalletInfo,
|
||||
};
|
||||
use crate::util::ToHex;
|
||||
use grin_wallet_util::OnionV3Address;
|
||||
@@ -634,3 +636,29 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Display a summary of a contract slate
|
||||
pub fn contract_view(slate: &Slate, view: &ContractView) {
|
||||
println!("\n____ Contract ____\n");
|
||||
let mut table = table!();
|
||||
|
||||
table.add_row(row![bFC->"Slate Id", bGC->slate.id]);
|
||||
table.add_row(row![bFC->"State", bGC->slate.state]);
|
||||
table.add_row(row![bFC->"Participants", bGC->view.num_participants]);
|
||||
table.add_row(row![bFC->"Signatures", bGC->view.num_sigs]);
|
||||
let suggested = match view.suggested_net_change {
|
||||
Some(v) => amount_to_hr_string(v.unsigned_abs(), false),
|
||||
None => String::from("None"),
|
||||
};
|
||||
table.add_row(row![bFC->"Suggested Net Change", bGC->suggested]);
|
||||
let agreed = match view.agreed_net_change {
|
||||
Some(v) => amount_to_hr_string(v.unsigned_abs(), false),
|
||||
None => String::from("None"),
|
||||
};
|
||||
table.add_row(row![bFC->"Agreed Net Change", bGC->agreed]);
|
||||
table.add_row(row![bFC->"Executed", bGC->view.is_executed]);
|
||||
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
table.printstd();
|
||||
println!();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user