You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,7 +13,7 @@ To illustrate, think of a bank vault that demands multiple keys to unlock; this
13
13
14
14
Advocates of multisignature wallets argue that they offer the most secure and fail-proof method for storing cryptocurrency. Even if a thief were to obtain one of the wallet keys, they would still be unable to access the account without the keys associated with the other wallets in the setup.
15
15
16
-
This article provides an explanation of the programming interface, data structure, basic functions, and their respective purposes. It can be used as-is or customized to fit specific needs. Anyone can create an application and deploy it on the Gear Network. The source codeis accessible on [GitHub](https://github.com/gear-foundation/dapps/tree/master/contracts/multisig-wallet).
16
+
This article provides an explanation of the programming interface, data structure, basic functions, and their respective purposes. It can be used as-is or customized to fit specific needs. Anyone can create an application and deploy it on the Gear Network. The source code, developed using the [Sails](../../build/sails/sails.mdx) framework, is available on [GitHub](https://github.com/gear-foundation/dapps/tree/master/contracts/multisig-wallet).
17
17
18
18
## Logic
19
19
@@ -35,55 +35,103 @@ The transaction approval logic is complex, for example:
-`required` - required confirmations count to approve and execute the transaction
52
+
*`transactions` - a mapping of `TransactionId` to `Transaction` that stores all transactions in the wallet
53
+
*`confirmations` - a mapping of `TransactionId` to a set of `ActorIds`, representing confirmations by each owner for specific transactions
54
+
*`owners` - a set of `ActorIds` representing the authorized owners of the wallet
55
+
*`required` - the number of confirmations required to execute a transaction
56
+
*`transaction_count` - a counter tracking the number of transactions
57
+
58
+
Where `Transaction` is defined as follows:
59
+
60
+
```rust title="multisig-wallet/app/src/utils.rs"
61
+
pubstructTransaction {
62
+
pubdestination:ActorId,
63
+
pubpayload:Vec<u8>,
64
+
pubvalue:u128,
65
+
pubdescription:Option<String>,
66
+
pubexecuted:bool,
67
+
}
68
+
```
50
69
51
-
### Actions
70
+
*`destination` - the account where the transaction funds or actions are directed
71
+
*`payload` - data related to the transaction, potentially containing specific instructions or actions
72
+
*`value` - the amount of funds or value to transfer
73
+
*`description` - an optional description providing context for the transaction
74
+
*`executed` - a boolean indicating if the transaction has been executed
52
75
53
-
```rust title="multisig-wallet/io/src/lib.rs"
54
-
pubenumMWAction {
55
-
AddOwner(ActorId),
56
-
RemoveOwner(ActorId),
57
-
ReplaceOwner {
58
-
old_owner:ActorId,
59
-
new_owner:ActorId,
60
-
},
61
-
ChangeRequiredConfirmationsCount(u32),
62
-
SubmitTransaction {
63
-
destination:ActorId,
64
-
data:Vec<u8>,
65
-
value:u128,
66
-
description:Option<String>,
67
-
},
68
-
ConfirmTransaction(U256),
69
-
RevokeConfirmation(U256),
70
-
ExecuteTransaction(U256),
76
+
### Initialization
77
+
78
+
During program initialization, the following variables are set: the list of wallet owners and the minimum number of confirmations required to execute a transaction.
-`AddOwner` is an action to add a new owner. The action has to be used through `SubmitTransaction`.
75
-
-`RemoveOwner` is an action to remove an owner. The action has to be used through `SubmitTransaction`.
76
-
-`ReplaceOwner` is an action to replace an owner with a new owner. The action has to be used through `SubmitTransaction`.
77
-
-`ChangeRequiredConfirmationsCount` is an action to change the number of required confirmations. The action has to be used through `SubmitTransaction`.
78
-
-`SubmitTransaction` is an action that allows an owner to submit and automatically confirm a transaction.
79
-
-`ConfirmTransaction` is an action that allows an owner to confirm a transaction. If this is the last confirmation, the transaction is automatically executed.
80
-
-`RevokeConfirmation` is an action that allows an owner to revoke a confirmation for a transaction.
81
-
-`ExecuteTransaction` is an action that allows anyone to execute a confirmed transaction.
-`add_owner` is an action to add a new owner. The action has to be used through `submit_transaction`.
123
+
-`remove_owner` is an action to remove an owner. The action has to be used through `submit_transaction`.
124
+
-`replace_owner` is an action to replace an owner with a new owner. The action has to be used through `submit_transaction`.
125
+
-`change_required_confirmations_count` is an action to change the number of required confirmations. The action has to be used through `submit_transaction`.
126
+
-`submit_transaction` is an action that allows an owner to submit and automatically confirm a transaction.
127
+
-`confirm_transaction` is an action that allows an owner to confirm a transaction. If this is the last confirmation, the transaction is automatically executed.
128
+
-`revoke_confirmation` is an action that allows an owner to revoke a confirmation for a transaction.
129
+
-`execute_transaction` is an action that allows anyone to execute a confirmed transaction.
82
130
83
131
### Events
84
132
85
-
```rust title="multisig-wallet/io/src/lib.rs"
86
-
pubenumMWEvent {
133
+
```rust title="multisig-wallet/app/src/lib.rs"
134
+
pubenumEvent {
87
135
Confirmation {
88
136
sender:ActorId,
89
137
transaction_id:U256,
@@ -121,150 +169,22 @@ pub enum MWEvent {
121
169
-`OwnerReplace` is an event that occurs when the wallet uses the `ReplaceOwner` action successfully.
122
170
-`RequirementChange` is an event that occurs when the wallet uses the `ChangeRequiredConfirmationsCount` action successfully.
123
171
124
-
### Program Metadata and State
125
-
126
-
Metadata interface description:
172
+
### Query
127
173
128
-
```rust title="multisig-wallet/io/src/lib.rs"
129
-
pubstructContractMetadata;
130
-
131
-
implMetadataforContractMetadata {
132
-
typeInit=In<MWInitConfig>;
133
-
typeHandle=InOut<MWAction, MWEvent>;
134
-
typeReply= ();
135
-
typeOthers= ();
136
-
typeSignal= ();
137
-
typeState=Out<State>;
138
-
}
139
-
```
140
-
To display the full contract state information, the `state()` function is used:
141
-
142
-
```rust title="multisig-wallet/src/lib.rs"
143
-
#[no_mangle]
144
-
externfnstate() {
145
-
letcontract=unsafe { WALLET.take().expect("Unexpected error in taking state") };
146
-
msg::reply::<State>(contract.into(), 0)
147
-
.expect("Failed to encode or reply with `State` from `state()`");
174
+
```rust title="multisig-wallet/app/src/lib.rs"
175
+
pubfnget_state(&self) ->State {
176
+
self.get().clone().into()
148
177
}
149
178
```
150
-
To display only specific values from the state, write a separate crate. In this crate, specify functions that will return the desired values from the `State` struct. For example, see [gear-foundation/dapps/multisig-wallet/state](https://github.com/gear-foundation/dapps/tree/master/contracts/multisig-wallet/state):
151
-
152
-
```rust title="multisig-wallet/state/src/lib.rs"
153
-
#[gmeta::metawasm]
154
-
pubmodmetafns {
155
-
pubtypeState=multisig_wallet_io::State;
156
-
157
-
/// Returns number of confirmations of a transaction.
-`ConfirmationsCount` returns the number of confirmations of a transaction whose ID is a parameter.
244
-
-`TransactionsCount` returns the total number of transactions after filters are applied. `pending` includes transactions that have not been executed yet, `executed` includes transactions that have been completed.
245
-
-`Owners` returns the list of owners.
246
-
-`Confirmations` returns an array with owner addresses that confirmed the transaction whose ID is a parameter.
247
-
-`TransactionIds` returns a list of transaction IDs in a defined range.
248
-
-`from` index start position of the transaction array.
249
-
-`to` index end position of the transaction array (not included).
250
-
-`pending` include pending transactions.
251
-
-`executed` include executed transactions.
252
-
-`IsConfirmed` returns the confirmation status of the transaction whose ID is a parameter.
253
-
-`Description` returns the description of the transaction whose ID is a parameter.
254
-
255
-
Each state request has a corresponding reply with the same name.
@@ -274,4 +194,4 @@ The source code of this example of a Multisig Wallet program and an implementati
274
194
275
195
See also an example of the program testing implementation based on `gtest`: [multisig-wallet/tests](https://github.com/gear-foundation/dapps/tree/master/contracts/multisig-wallet/tests).
276
196
277
-
For more details about testing program written on Vara, refer to the [Program Testing](/docs/build/testing) article.
197
+
For more details about testing program written on Vara, refer to the [Program Testing](/docs/build/testing) article.
0 commit comments