Skip to content

Commit 5997ed9

Browse files
Merge pull request #78 from ElrondNetwork/multisig-fix-8
Multisig - send tx with message
2 parents beef1df + 3fda3bb commit 5997ed9

File tree

16 files changed

+124
-69
lines changed

16 files changed

+124
-69
lines changed

contracts/examples/crowdfunding-egld/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ pub trait Crowdfunding {
6262
if &caller != &self.get_owner() {
6363
return sc_error!("only owner can claim successful funding");
6464
}
65-
self.send_tx(&caller, &self.get_sc_balance(), "funding success");
65+
self.send_tx(&caller, &self.get_sc_balance(), b"funding success");
6666
Ok(())
6767
},
6868
Status::Failed => {
6969
let caller = self.get_caller();
7070
let deposit = self.get_deposit(&caller);
7171
if &deposit > &0 {
72-
self.send_tx(&caller, &deposit, "reclaim failed funding");
72+
self.send_tx(&caller, &deposit, b"reclaim failed funding");
7373
self.set_deposit(&caller, &BigUint::zero());
7474
}
7575
Ok(())

contracts/examples/crypto-bubbles/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub trait CryptoBubbles {
4545
balance -= amount;
4646
self.set_player_balance(player, &balance);
4747

48-
self.send_tx(player, &amount, "crypto bubbles");
48+
self.send_tx(player, &amount, b"crypto bubbles");
4949

5050
self.withdraw_event(player, amount);
5151

contracts/examples/lottery-egld/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ pub trait Lottery {
174174
return Status::Running;
175175
}
176176

177-
fn update_after_buy_ticket(&self, lottery_name: &BoxedBytes, payment: &BigUint) -> SCResult<()> {
177+
fn update_after_buy_ticket(
178+
&self,
179+
lottery_name: &BoxedBytes,
180+
payment: &BigUint,
181+
) -> SCResult<()> {
178182
let mut info = self.get_lottery_info(&lottery_name);
179183
let caller = self.get_caller();
180184

@@ -254,7 +258,7 @@ pub trait Lottery {
254258
self.send_tx(
255259
&winner_address,
256260
&prize,
257-
"You won the lottery! Congratulations!",
261+
b"You won the lottery! Congratulations!",
258262
);
259263
info.prize_pool -= prize;
260264

@@ -321,20 +325,12 @@ pub trait Lottery {
321325
&self,
322326
lottery_name: &BoxedBytes,
323327
user: &Address,
324-
nr_entries: u32
328+
nr_entries: u32,
325329
);
326330

327331
#[storage_get("numberOfEntriesForUser")]
328-
fn get_number_of_entries_for_user(
329-
&self,
330-
lottery_name: &BoxedBytes,
331-
user: &Address,
332-
) -> u32;
332+
fn get_number_of_entries_for_user(&self, lottery_name: &BoxedBytes, user: &Address) -> u32;
333333

334334
#[storage_clear("numberOfEntriesForUser")]
335-
fn clear_number_of_entries_for_user(
336-
&self,
337-
lottery_name: &BoxedBytes,
338-
user: &Address
339-
);
335+
fn clear_number_of_entries_for_user(&self, lottery_name: &BoxedBytes, user: &Address);
340336
}

contracts/examples/lottery-erc20/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,22 +425,14 @@ pub trait Lottery {
425425
&self,
426426
lottery_name: &BoxedBytes,
427427
user: &Address,
428-
nr_entries: u32
428+
nr_entries: u32,
429429
);
430430

431431
#[storage_get("numberOfEntriesForUser")]
432-
fn get_number_of_entries_for_user(
433-
&self,
434-
lottery_name: &BoxedBytes,
435-
user: &Address,
436-
) -> u32;
432+
fn get_number_of_entries_for_user(&self, lottery_name: &BoxedBytes, user: &Address) -> u32;
437433

438434
#[storage_clear("numberOfEntriesForUser")]
439-
fn clear_number_of_entries_for_user(
440-
&self,
441-
lottery_name: &BoxedBytes,
442-
user: &Address
443-
);
435+
fn clear_number_of_entries_for_user(&self, lottery_name: &BoxedBytes, user: &Address);
444436

445437
#[storage_set("erc20_contract_address")]
446438
fn set_erc20_contract_address(&self, address: &Address);

contracts/examples/lottery-esdt/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,12 @@ pub trait Lottery {
344344
&self,
345345
lottery_name: &BoxedBytes,
346346
user: &Address,
347-
nr_entries: u32
347+
nr_entries: u32,
348348
);
349349

350350
#[storage_get("numberOfEntriesForUser")]
351-
fn get_number_of_entries_for_user(
352-
&self,
353-
lottery_name: &BoxedBytes,
354-
user: &Address,
355-
) -> u32;
351+
fn get_number_of_entries_for_user(&self, lottery_name: &BoxedBytes, user: &Address) -> u32;
356352

357353
#[storage_clear("numberOfEntriesForUser")]
358-
fn clear_number_of_entries_for_user(
359-
&self,
360-
lottery_name: &BoxedBytes,
361-
user: &Address
362-
);
354+
fn clear_number_of_entries_for_user(&self, lottery_name: &BoxedBytes, user: &Address);
363355
}

contracts/examples/lottery-esdt/src/lottery_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use elrond_wasm::elrond_codec::*;
2-
use elrond_wasm::{Address, BoxedBytes, BigUintApi, Vec};
2+
use elrond_wasm::{Address, BigUintApi, BoxedBytes, Vec};
33

44
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
55
pub struct LotteryInfo<BigUint: BigUintApi> {

contracts/examples/multisig/src/action.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum Action<BigUint: BigUintApi> {
1010
SendEgld {
1111
to: Address,
1212
amount: BigUint,
13+
data: BoxedBytes,
1314
},
1415
SCDeploy {
1516
amount: BigUint,
@@ -56,10 +57,11 @@ impl<BigUint: BigUintApi> NestedEncode for Action<BigUint> {
5657
4u8.dep_encode_or_exit(dest, c.clone(), exit);
5758
new_quorum.dep_encode_or_exit(dest, c.clone(), exit);
5859
},
59-
Action::SendEgld { to, amount } => {
60+
Action::SendEgld { to, amount, data } => {
6061
5u8.dep_encode_or_exit(dest, c.clone(), exit);
6162
to.dep_encode_or_exit(dest, c.clone(), exit);
6263
amount.dep_encode_or_exit(dest, c.clone(), exit);
64+
data.dep_encode_or_exit(dest, c.clone(), exit);
6365
},
6466
Action::SCDeploy {
6567
amount,
@@ -129,6 +131,7 @@ impl<BigUint: BigUintApi> NestedDecode for Action<BigUint> {
129131
5 => Action::SendEgld {
130132
to: Address::dep_decode_or_exit(input, c.clone(), exit),
131133
amount: BigUint::dep_decode_or_exit(input, c.clone(), exit),
134+
data: BoxedBytes::dep_decode_or_exit(input, c.clone(), exit),
132135
},
133136
6 => Action::SCDeploy {
134137
amount: BigUint::dep_decode_or_exit(input, c.clone(), exit),

contracts/examples/multisig/src/lib.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ pub trait Multisig {
7979

8080
#[init]
8181
fn init(&self, quorum: usize, #[var_args] board: VarArgs<Address>) -> SCResult<()> {
82-
require!(board.len() > 0, "board cannot be empty on init, no-one would be able to propose");
82+
require!(
83+
board.len() > 0,
84+
"board cannot be empty on init, no-one would be able to propose"
85+
);
8386
require!(quorum <= board.len(), "quorum cannot exceed board size");
8487
self.set_quorum(quorum);
8588

@@ -143,8 +146,17 @@ pub trait Multisig {
143146
}
144147

145148
#[endpoint(proposeSendEgld)]
146-
fn propose_send_egld(&self, to: Address, amount: BigUint) -> SCResult<usize> {
147-
self.propose_action(Action::SendEgld { to, amount })
149+
fn propose_send_egld(
150+
&self,
151+
to: Address,
152+
amount: BigUint,
153+
#[var_args] opt_data: OptionalArg<BoxedBytes>,
154+
) -> SCResult<usize> {
155+
let data = match opt_data {
156+
OptionalArg::Some(data) => data,
157+
OptionalArg::None => BoxedBytes::empty(),
158+
};
159+
self.propose_action(Action::SendEgld { to, amount, data })
148160
}
149161

150162
#[endpoint(proposeSCDeploy)]
@@ -214,7 +226,10 @@ pub trait Multisig {
214226

215227
#[endpoint]
216228
fn sign(&self, action_id: usize) -> SCResult<()> {
217-
require!(!self.is_empty_action_data(action_id), "action does not exist");
229+
require!(
230+
!self.is_empty_action_data(action_id),
231+
"action does not exist"
232+
);
218233

219234
let caller_address = self.get_caller();
220235
let caller_id = self.users_module().get_user_id(&caller_address);
@@ -232,7 +247,10 @@ pub trait Multisig {
232247

233248
#[endpoint]
234249
fn unsign(&self, action_id: usize) -> SCResult<()> {
235-
require!(!self.is_empty_action_data(action_id), "action does not exist");
250+
require!(
251+
!self.is_empty_action_data(action_id),
252+
"action does not exist"
253+
);
236254

237255
let caller_address = self.get_caller();
238256
let caller_id = self.users_module().get_user_id(&caller_address);
@@ -320,7 +338,6 @@ pub trait Multisig {
320338
signer_ids
321339
.iter()
322340
.filter(|signer_id| {
323-
324341
let signer_role = self.get_user_id_to_role(**signer_id);
325342
signer_role.can_sign()
326343
})
@@ -343,7 +360,10 @@ pub trait Multisig {
343360
caller_role.can_perform_action(),
344361
"only board members and proposers can perform actions"
345362
);
346-
require!(self.quorum_reached(action_id), "quorum has not been reached");
363+
require!(
364+
self.quorum_reached(action_id),
365+
"quorum has not been reached"
366+
);
347367

348368
self.perform_action(action_id)
349369
}
@@ -387,8 +407,8 @@ pub trait Multisig {
387407
);
388408
self.set_quorum(new_quorum)
389409
},
390-
Action::SendEgld { to, amount } => {
391-
self.send_tx(&to, &amount, "");
410+
Action::SendEgld { to, amount, data } => {
411+
self.send_tx(&to, &amount, data.as_slice());
392412
},
393413
Action::SCDeploy {
394414
amount,

contracts/examples/multisig/src/user_role.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl UserRole {
2121

2222
pub fn can_sign(&self) -> bool {
2323
match *self {
24-
UserRole::BoardMember => true,
24+
UserRole::BoardMember => true,
2525
_ => false,
2626
}
2727
}

contracts/feature-tests/basic-features/mandos/send_tx.scen.json

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"step": "setState",
66
"accounts": {
77
"address:features_contract": {
8-
"nonce": "0",
9-
"balance": "100",
8+
"nonce": "1000",
9+
"balance": "200",
1010
"storage": {},
1111
"code": "file:../output/basic-features.wasm"
1212
},
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"step": "scCall",
23-
"txId": "1",
23+
"txId": "not-enough",
2424
"tx": {
2525
"from": "address:an_account",
2626
"to": "address:features_contract",
@@ -39,6 +39,49 @@
3939
"message": "str:failed transfer (insufficient funds)",
4040
"logs": []
4141
}
42+
},
43+
{
44+
"step": "scCall",
45+
"txId": "without-message",
46+
"tx": {
47+
"from": "address:an_account",
48+
"to": "address:features_contract",
49+
"value": "0",
50+
"function": "send_tx_endpoint",
51+
"arguments": [
52+
"address:an_account",
53+
"100"
54+
],
55+
"gasLimit": "0x100000",
56+
"gasPrice": "0"
57+
},
58+
"expect": {
59+
"out": [],
60+
"status": "",
61+
"logs": []
62+
}
63+
},
64+
{
65+
"step": "scCall",
66+
"txId": "with-message",
67+
"tx": {
68+
"from": "address:an_account",
69+
"to": "address:features_contract",
70+
"value": "0",
71+
"function": "send_tx_endpoint",
72+
"arguments": [
73+
"address:an_account",
74+
"100",
75+
"str:send tx message here"
76+
],
77+
"gasLimit": "0x100000",
78+
"gasPrice": "0"
79+
},
80+
"expect": {
81+
"out": [],
82+
"status": "",
83+
"logs": []
84+
}
4285
}
4386
]
4487
}

0 commit comments

Comments
 (0)