Skip to content

Commit 237e336

Browse files
tmpolaczyklrubiorod
andcommitted
feat: Allow using custom change address in sendvtt
Co-authored-by: Luis Rubio <l.rubiorod@gmail.com>
1 parent 6b937ef commit 237e336

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

data_structures/src/transaction_factory.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ pub fn build_vtt(
347347
utxo_strategy: &UtxoSelectionStrategy,
348348
max_weight: u32,
349349
additional_inputs: Vec<Input>,
350+
change_address: Option<PublicKeyHash>,
350351
) -> Result<VTTransactionBody, TransactionError> {
351352
let mut utxos = NodeUtxos {
352353
all_utxos,
@@ -377,7 +378,7 @@ pub fn build_vtt(
377378
let mut outputs = tx_info.outputs;
378379
insert_change_output(
379380
&mut outputs,
380-
own_pkh,
381+
change_address.unwrap_or(own_pkh),
381382
tx_info.input_value - tx_info.output_value - tx_info.fee,
382383
);
383384

node/src/actors/chain_manager/handlers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ impl Handler<BuildVtt> for ChainManager {
12371237
&msg.utxo_strategy,
12381238
max_vt_weight,
12391239
vec![],
1240+
msg.change_address,
12401241
) {
12411242
Err(e) => {
12421243
log::error!("Error when building value transfer transaction: {}", e);
@@ -1298,6 +1299,7 @@ impl Handler<BuildScriptTransaction> for ChainManager {
12981299
&msg.utxo_strategy,
12991300
max_vt_weight,
13001301
msg.script_inputs,
1302+
msg.change_address,
13011303
) {
13021304
Err(e) => {
13031305
log::error!("Error when building value transfer transaction: {}", e);

node/src/actors/messages.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ pub struct BuildVtt {
203203
/// Strategy to sort the unspent outputs pool
204204
#[serde(default)]
205205
pub utxo_strategy: UtxoSelectionStrategy,
206+
/// Change address
207+
pub change_address: Option<PublicKeyHash>,
206208
}
207209

208210
impl Message for BuildVtt {
@@ -221,6 +223,8 @@ pub struct BuildScriptTransaction {
221223
pub utxo_strategy: UtxoSelectionStrategy,
222224
/// Extra script inputs
223225
pub script_inputs: Vec<Input>,
226+
/// Change address
227+
pub change_address: Option<PublicKeyHash>,
224228
}
225229

226230
impl Message for BuildScriptTransaction {

src/cli/node/json_rpc_client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ pub fn get_output(addr: SocketAddr, pointer: String) -> Result<(), failure::Erro
552552
pub fn send_vtt(
553553
addr: SocketAddr,
554554
pkh: Option<PublicKeyHash>,
555+
change_address: Option<PublicKeyHash>,
555556
value: u64,
556557
size: Option<u64>,
557558
fee: u64,
@@ -606,6 +607,7 @@ pub fn send_vtt(
606607
vto: vt_outputs,
607608
fee,
608609
utxo_strategy,
610+
change_address,
609611
};
610612

611613
let request = format!(
@@ -756,6 +758,7 @@ pub fn create_opened_multisig(
756758
n: u8,
757759
m: u8,
758760
pkhs: Vec<PublicKeyHash>,
761+
change_address: Option<PublicKeyHash>,
759762
address: PublicKeyHash,
760763
dry_run: bool,
761764
) -> Result<(), failure::Error> {
@@ -793,6 +796,7 @@ pub fn create_opened_multisig(
793796
fee,
794797
utxo_strategy,
795798
script_inputs,
799+
change_address,
796800
};
797801
let request = format!(
798802
r#"{{"jsonrpc": "2.0","method": "sendScript", "params": {}, "id": "1"}}"#,

src/cli/node/with_node.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ pub fn exec_cmd(
9393
Command::Send {
9494
node,
9595
address,
96+
change_address,
9697
value,
9798
fee,
9899
time_lock,
99100
dry_run,
100101
} => rpc::send_vtt(
101102
node.unwrap_or(config.jsonrpc.server_address),
102103
Some(address.parse()?),
104+
change_address.map(|address| address.parse()).transpose()?,
103105
value,
104106
None,
105107
fee,
@@ -110,6 +112,7 @@ pub fn exec_cmd(
110112
Command::Split {
111113
node,
112114
address,
115+
change_address,
113116
value,
114117
size,
115118
fee,
@@ -121,6 +124,7 @@ pub fn exec_cmd(
121124
rpc::send_vtt(
122125
node.unwrap_or(config.jsonrpc.server_address),
123126
address,
127+
change_address.map(|address| address.parse()).transpose()?,
124128
value,
125129
size,
126130
fee,
@@ -132,6 +136,7 @@ pub fn exec_cmd(
132136
Command::Join {
133137
node,
134138
address,
139+
change_address,
135140
value,
136141
size,
137142
fee,
@@ -143,6 +148,7 @@ pub fn exec_cmd(
143148
rpc::send_vtt(
144149
node.unwrap_or(config.jsonrpc.server_address),
145150
address,
151+
change_address.map(|address| address.parse()).transpose()?,
146152
value,
147153
size,
148154
fee,
@@ -177,6 +183,7 @@ pub fn exec_cmd(
177183
n,
178184
m,
179185
pkhs,
186+
change_address,
180187
address,
181188
dry_run,
182189
} => rpc::create_opened_multisig(
@@ -189,6 +196,7 @@ pub fn exec_cmd(
189196
pkhs.into_iter()
190197
.map(|address| address.parse())
191198
.collect::<Result<Vec<_>, _>>()?,
199+
change_address.map(|address| address.parse()).transpose()?,
192200
address.parse()?,
193201
dry_run,
194202
),
@@ -510,6 +518,9 @@ pub enum Command {
510518
/// Address of the destination
511519
#[structopt(long = "address", alias = "pkh")]
512520
address: String,
521+
/// Change address
522+
#[structopt(long = "change-address")]
523+
change_address: Option<String>,
513524
/// Value
514525
#[structopt(long = "value")]
515526
value: u64,
@@ -534,6 +545,9 @@ pub enum Command {
534545
/// Public key hash of the destination. If omitted, defaults to the node pkh
535546
#[structopt(long = "address", alias = "pkh")]
536547
address: Option<String>,
548+
/// Change address
549+
#[structopt(long = "change-address")]
550+
change_address: Option<String>,
537551
/// Value
538552
#[structopt(long = "value")]
539553
value: u64,
@@ -561,6 +575,9 @@ pub enum Command {
561575
/// Public key hash of the destination. If omitted, defaults to the node pkh
562576
#[structopt(long = "address", alias = "pkh")]
563577
address: Option<String>,
578+
/// Change address
579+
#[structopt(long = "change-address")]
580+
change_address: Option<String>,
564581
/// Value
565582
#[structopt(long = "value")]
566583
value: u64,
@@ -636,6 +653,9 @@ pub enum Command {
636653
/// List of pkhs
637654
#[structopt(long = "pkhs")]
638655
pkhs: Vec<String>,
656+
/// Change address
657+
#[structopt(long = "change-address")]
658+
change_address: Option<String>,
639659
/// Address of the destination
640660
#[structopt(long = "address", alias = "pkh")]
641661
address: String,

0 commit comments

Comments
 (0)