Skip to content

Commit 469347a

Browse files
dboreham0xzoz
authored andcommitted
[tools] Batch cw instr (#237)
Co-authored-by: zoz <[email protected]>
1 parent cf1dc92 commit 469347a

File tree

9 files changed

+1787
-1529
lines changed

9 files changed

+1787
-1529
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework/libra-framework/sources/ol_sources/vote_lib/donor_voice_txs.move

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,6 @@ module ol_framework::donor_voice_txs {
371371
while (i < len) {
372372

373373
let t = vector::pop_back(&mut due_list);
374-
// if (this_exp <= epoch) {
375-
// let t = vector::remove(&mut state.scheduled, i);
376374
let multisig_address = guid::id_creator_address(&t.uid);
377375

378376
// Note the VM can do this without the WithdrawCapability
@@ -393,7 +391,6 @@ module ol_framework::donor_voice_txs {
393391

394392

395393
vector::push_back(&mut state.paid, t);
396-
// print(is_paid());
397394
print(&state.scheduled);
398395
print(&state.paid);
399396
} else {
@@ -406,7 +403,7 @@ module ol_framework::donor_voice_txs {
406403

407404
amount_processed = amount_processed + amount_transferred;
408405

409-
// if theres a single transaction that gets approved, then the freeze consecutive rejection counter is reset
406+
// if there's a single transaction that gets approved, then the freeze consecutive rejection counter is reset
410407
reset_rejection_counter(vm, multisig_address);
411408

412409
i = i + 1;

framework/libra-framework/sources/ol_sources/vote_lib/multi_action.move

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,19 @@ module ol_framework::multi_action {
534534
ballot::find_anywhere(&a.vote, uid)
535535
}
536536

537+
/// get all IDs of multi_auth proposal that are pending
538+
fun get_pending_id<ProposalData: store + drop>(multisig_address: address): vector<guid::ID> acquires Action {
539+
let action = borrow_global<Action<ProposalData>>(multisig_address);
540+
let list = ballot::get_list_ballots_by_enum(&action.vote,
541+
ballot::get_pending_enum());
542+
543+
let id_list = vector::map_ref(list, |el| {
544+
ballot::get_ballot_id(el)
545+
});
546+
547+
id_list
548+
}
549+
537550

538551
//////// GOVERNANCE ////////
539552
// Governance of the multisig happens through an instance of Action<PropGovSigners>. This action has no special privileges, and is just a normal proposal type.
@@ -612,12 +625,22 @@ module ol_framework::multi_action {
612625
}
613626

614627
#[view]
628+
/// how many multi_action proposals are pending
615629
public fun get_count_of_pending<ProposalData: store + drop>(multisig_address: address): u64 acquires Action {
616-
let action = borrow_global<Action<ProposalData>>(multisig_address);
617-
let list = ballot::get_list_ballots_by_enum(&action.vote, ballot::get_pending_enum());
618-
vector::length(list)
630+
let list = get_pending_id<ProposalData>(multisig_address);
631+
vector::length(&list)
619632
}
620633

634+
#[view]
635+
/// the creation number u64 of the pending proposals
636+
public fun get_pending_by_creation_number<ProposalData: store + drop>(multisig_address: address): vector<u64> acquires Action {
637+
let list = get_pending_id<ProposalData>(multisig_address);
638+
vector::map(list, |el| {
639+
guid::id_creation_num(&el)
640+
})
641+
}
642+
643+
621644
#[view]
622645
/// returns the votes for a given proposal ID. For `view` functions must provide the destructured guid::ID as address and integer.
623646
public fun get_votes<ProposalData: store + drop>(multisig_address: address, id_num: u64): vector<address> acquires Action {

tools/query/src/account_queries.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use libra_types::{
1111
type_extensions::client_ext::{entry_function_id, ClientExt},
1212
};
1313

14-
use serde_json::json;
14+
use serde_json::{json, Value};
1515
/// helper to get libra balance at a SlowWalletBalance type which shows
1616
/// total balance and the unlocked balance.
1717
pub async fn get_account_balance_libra(
@@ -107,9 +107,23 @@ pub async fn community_wallet_signers(
107107
Ok(json!(res))
108108
}
109109

110-
pub async fn community_wallet_pending_transactions(
110+
pub async fn community_wallet_scheduled_transactions(
111111
client: &Client,
112112
account: AccountAddress,
113113
) -> anyhow::Result<TxSchedule> {
114114
client.get_move_resource::<TxSchedule>(account).await
115115
}
116+
117+
/// get all of the multi_auth actions, pending, approved, expired.
118+
pub async fn multi_auth_ballots(
119+
client: &Client,
120+
multi_auth_account: AccountAddress,
121+
) -> anyhow::Result<Value> {
122+
let resource_path_str = "0x1::multi_action::Action<0x1::donor_voice_txs::Payment>";
123+
let proposal_state = client
124+
.get_account_resource(multi_auth_account, resource_path_str)
125+
.await?;
126+
let r = proposal_state.inner().clone().unwrap();
127+
128+
Ok(r.data)
129+
}

tools/query/src/chain_queries.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,11 @@ pub async fn can_gov_proposal_resolve(client: &Client, id: u64) -> anyhow::Resul
6464
client,
6565
"0x1::diem_governance::get_can_resolve",
6666
None,
67-
Some(id.to_string()), //Some(format!("{}u64", id)),
67+
Some(id.to_string()),
6868
)
6969
.await?;
70-
// let id: Vec<String> = serde_json::from_value(query_res)?;
70+
7171
serde_json::from_value::<bool>(query_res).context("cannot parse api res")
72-
// .into_iter()
73-
// .next()
74-
// .context("could not get a response from view function can_resolve")
7572
}
7673

7774
// TODO: code duplication
@@ -80,10 +77,10 @@ pub async fn is_gov_proposal_resolved(client: &Client, id: u64) -> anyhow::Resul
8077
client,
8178
"0x1::diem_governance::is_resolved",
8279
None,
83-
Some(id.to_string()), //Some(format!("{}u64", id)),
80+
Some(id.to_string()),
8481
)
8582
.await?;
86-
// let id: Vec<String> = serde_json::from_value(query_res)?;
83+
8784
serde_json::from_value::<Vec<bool>>(query_res)?
8885
.into_iter()
8986
.next()
@@ -96,10 +93,10 @@ pub async fn get_gov_proposal_votes(client: &Client, id: u64) -> anyhow::Result<
9693
client,
9794
"0x1::diem_governance::get_votes",
9895
None,
99-
Some(id.to_string()), //Some(format!("{}u64", id)),
96+
Some(id.to_string()),
10097
)
10198
.await?;
102-
// let id: Vec<String> = serde_json::from_value(query_res)?;
99+
103100
Ok(serde_json::from_value::<Vec<u128>>(query_res)?)
104101
}
105102

tools/query/src/query_type.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::{
22
account_queries::{
3-
community_wallet_pending_transactions, community_wallet_signers, get_account_balance_libra,
4-
get_events, get_transactions, get_val_config, is_community_wallet_migrated,
3+
community_wallet_scheduled_transactions, community_wallet_signers,
4+
get_account_balance_libra, get_events, get_transactions, get_val_config,
5+
is_community_wallet_migrated,
56
},
67
chain_queries::{get_epoch, get_height},
78
query_view::get_view,
@@ -264,7 +265,7 @@ impl QueryType {
264265
}
265266
QueryType::ComWalletPendTransactions { account } => {
266267
// Wont work at the moment as there is no community wallet migrated
267-
let _res = community_wallet_pending_transactions(&client, *account).await?;
268+
let _res = community_wallet_scheduled_transactions(&client, *account).await?;
268269
Ok(json!({ "pending_transactions": "None" }))
269270
}
270271
QueryType::Annotate { account } => {

0 commit comments

Comments
 (0)