merge staging

This commit is contained in:
wiesche
2026-09-15 22:30:41 +02:00
12 changed files with 146 additions and 40 deletions
+38
View File
@@ -842,6 +842,25 @@ where
args.input_file,
args.input_slatepack_message,
)?;
match slate.state {
SlateState::Invoice1 => {
return Err(Error::GenericError(
"Use the 'pay' command to process this invoice transaction".to_string(),
))
}
SlateState::Standard2 | SlateState::Invoice2 => {
return Err(Error::GenericError(
"Use the 'finalize' command to complete this transaction".to_string(),
))
}
SlateState::Standard3 | SlateState::Invoice3 => {
return Err(Error::GenericError(
"Use the 'post' command to post this finalized transaction to the chain"
.to_string(),
))
}
_ => {}
}
let km = match keychain_mask.as_ref() {
None => None,
@@ -1005,6 +1024,25 @@ where
args.input_file.clone(),
args.input_slatepack_message.clone(),
)?;
match slate.state {
SlateState::Standard1 => {
return Err(Error::GenericError(
"Use the 'receive' command on the recipient's wallet first".to_string(),
))
}
SlateState::Invoice1 => {
return Err(Error::GenericError(
"Use the 'pay' command on the payer's wallet first".to_string(),
))
}
SlateState::Standard3 | SlateState::Invoice3 => {
return Err(Error::GenericError(
"Use the 'post' command to post this finalized transaction to the chain"
.to_string(),
))
}
_ => {}
}
// Rather than duplicating the entire command, we'll just
// try to determine what kind of finalization this is
+3 -7
View File
@@ -66,22 +66,18 @@ lazy_static! {
fn check_middleware(
name: ForeignCheckMiddlewareFn,
node_version_info: Option<NodeVersionInfo>,
_node_version_info: Option<NodeVersionInfo>,
slate: Option<&Slate>,
) -> Result<(), Error> {
match name {
// allow coinbases to be built regardless
ForeignCheckMiddlewareFn::BuildCoinbase => Ok(()),
_ => {
let mut bhv = 3;
if let Some(n) = node_version_info {
bhv = n.block_header_version;
}
if let Some(s) = slate {
if bhv > 4 && s.version_info.block_header_version < GRIN_BLOCK_HEADER_VERSION {
if s.version_info.block_header_version > GRIN_BLOCK_HEADER_VERSION {
Err(Error::Compatibility(
"Incoming Slate is not compatible with this wallet. \
Please upgrade the node or use a different one."
Please upgrade the wallet."
.into(),
))?;
}
+4 -5
View File
@@ -17,12 +17,11 @@ use crate::core::core::{self, amount_to_hr_string, Inputs, OutputFeatures};
use crate::core::global;
use crate::libwallet::contract::types::{ContractView, OwnCommitmentStatus};
use crate::libwallet::{
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, Slate, TxLogEntry, ViewWallet,
WalletInfo,
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, Slate, SlatepackAddress, TxLogEntry,
ViewWallet, WalletInfo,
};
use crate::util::secp::pedersen::Commitment;
use crate::util::ToHex;
use grin_wallet_util::OnionV3Address;
use prettytable;
use std::io::prelude::Write;
use term;
@@ -615,7 +614,7 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
writeln!(
t,
"Receiver Address: {}",
OnionV3Address::from_bytes(pp.receiver_address.to_bytes())
SlatepackAddress::new(&pp.receiver_address)
)
.unwrap();
writeln!(t, "Receiver Signature: {}", receiver_signature).unwrap();
@@ -624,7 +623,7 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
writeln!(
t,
"Sender Address: {}",
OnionV3Address::from_bytes(pp.sender_address.to_bytes())
SlatepackAddress::new(&pp.sender_address)
)
.unwrap();
writeln!(t, "Sender Signature: {}", sender_signature).unwrap();
+38
View File
@@ -124,6 +124,44 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
)?;
assert_eq!(slate.state, SlateState::Invoice1);
let receive_result = wallet::controller::foreign_single_use(
wallet1.clone(),
PathBuf::from(test_dir),
mask1_i.clone(),
|api| api.receive_tx(&slate, None, None).map(|_| ()),
);
assert_eq!(receive_result, Err(libwallet::Error::SlateState));
wallet::controller::owner_single_use(
wallet1.clone(),
mask1,
PathBuf::from(test_dir),
|api, m| {
let (_, txs) = api.retrieve_txs(m, false, None, Some(slate.id), None)?;
assert!(txs.is_empty());
Ok(())
},
)?;
// receive must reject every slate state except S1
for state in [
SlateState::Unknown,
SlateState::Standard2,
SlateState::Standard3,
SlateState::Invoice1,
SlateState::Invoice2,
SlateState::Invoice3,
] {
let mut bad_slate = slate.clone();
bad_slate.state = state.clone();
let res = wallet::controller::foreign_single_use(
wallet1.clone(),
PathBuf::from(test_dir),
mask1_i.clone(),
|api| api.receive_tx(&bad_slate, None, None).map(|_| ()),
);
assert_eq!(res, Err(libwallet::Error::SlateState), "state {}", state);
}
wallet::controller::owner_single_use(
wallet1.clone(),
mask1,
+23 -1
View File
@@ -23,7 +23,7 @@ use grin_core as core;
use self::core::core::transaction;
use self::core::core::Transaction;
use self::core::global;
use self::libwallet::{InitTxArgs, OutputStatus, Slate, SlateState};
use self::libwallet::{InitTxArgs, OutputStatus, Slate, SlateState, GRIN_BLOCK_HEADER_VERSION};
use impls::test_framework::{self, LocalWalletClient};
use std::convert::TryInto;
use std::path::PathBuf;
@@ -105,6 +105,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
// assert wallet contents
// and a single use api for a send command
let amount = 60_000_000_000;
let header_version = core::consensus::header_version(chain.head().unwrap().height).0;
let mut slate = Slate::blank(1, false);
wallet::controller::owner_single_use(
wallet1.clone(),
@@ -124,6 +125,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
let slate_i = sender_api.init_send_tx(m, args)?;
assert_eq!(slate_i.state, SlateState::Standard1);
assert_eq!(slate_i.version_info.block_header_version, header_version);
// Check we are creating a tx with the expected lock_height of 0.
// We will check this produces a Plain kernel later.
@@ -131,6 +133,26 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
assert_eq!(slate.state, SlateState::Standard2);
// wallet2 already has this slate, so accepted versions fail on the duplicate check
for bhv in 1..=GRIN_BLOCK_HEADER_VERSION + 1 {
let mut s = slate_i.clone();
s.version_info.block_header_version = bhv;
let res = wallet::controller::foreign_single_use(
wallet2.clone(),
PathBuf::from(test_dir),
mask2_i.clone(),
|api| api.receive_tx(&s, None, None).map(|_| ()),
);
if bhv <= GRIN_BLOCK_HEADER_VERSION {
assert!(matches!(
res,
Err(libwallet::Error::TransactionAlreadyReceived(_))
));
} else {
assert!(matches!(res, Err(libwallet::Error::Compatibility(_))));
}
}
sender_api.tx_lock_outputs(m, &slate)?;
slate = sender_api.finalize_tx(m, &slate)?;
assert_eq!(slate.state, SlateState::Standard3);