Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore - Bump shared to namada 0.41.0 #948

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
476 changes: 194 additions & 282 deletions packages/shared/lib/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/shared/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ chrono = "0.4.22"
getrandom = { version = "0.2.7", features = ["js"] }
gloo-utils = { version = "0.1.5", features = ["serde"] }
js-sys = "0.3.60"
namada = { git = "https://github.com/anoma/namada", version = "0.40.0", default-features = false, features = ["namada-sdk"] }
namada = { git = "https://github.com/anoma/namada", version = "0.41.0", default-features = false, features = ["namada-sdk"] }
rand = "0.8.5"
rexie = "0.5"
serde = "^1.0.181"
Expand Down
138 changes: 17 additions & 121 deletions packages/shared/lib/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use namada::ledger::queries::RPC;
use namada::masp::ExtendedViewingKey;
use namada::proof_of_stake::Epoch;
use namada::sdk::hash::Hash;
use namada::sdk::masp::{DefaultLogger, ShieldedContext};
use namada::sdk::masp::ShieldedContext;
use namada::sdk::masp_primitives::asset_type::AssetType;
use namada::sdk::masp_primitives::sapling::ViewingKey;
use namada::sdk::masp_primitives::transaction::components::ValueSum;
Expand All @@ -27,8 +27,8 @@ use namada::sdk::rpc::{
};
use namada::sdk::state::Key;
use namada::sdk::tx::{
TX_BOND_WASM, TX_REDELEGATE_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM, TX_UNBOND_WASM,
TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, TX_CLAIM_REWARDS_WASM
TX_BOND_WASM, TX_CLAIM_REWARDS_WASM, TX_REDELEGATE_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM,
TX_UNBOND_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM,
};
use namada::token;
use namada::uint::I256;
Expand Down Expand Up @@ -266,7 +266,8 @@ impl Query {
}

pub async fn shielded_sync(&self, owners: Box<[JsValue]>) -> Result<(), JsError> {
let owners: Vec<ViewingKey> = owners
// TODO: Can this be re-enabled?
let _owners: Vec<ViewingKey> = owners
.into_iter()
.filter_map(|owner| owner.as_string())
.map(|o| {
Expand All @@ -288,17 +289,18 @@ impl Query {

let _ = shielded.save().await?;

shielded
.fetch(
&self.client,
&DefaultLogger::new(&WebIo),
None,
None,
1,
&[],
&owners,
)
.await?;
// TODO: Can we still do the following? shielded.fetch() and DefaultLogger no longer exist:
// shielded.
// .fetch(
// &self.client,
// // &DefaultLogger::new(&WebIo),
// None,
// None,
// 1,
// &[],
// &owners,
// )
// .await?;

Ok(())
}
Expand Down Expand Up @@ -471,25 +473,6 @@ impl Query {
) -> Result<JsValue, JsError> {
let votes = compute_proposal_votes(&self.client, proposal_id, Epoch(epoch)).await;

//let result = query_proposal_votes(&self.client, id).await?;

//let votes: Vec<(Address, String, bool)> = result
// .into_iter()
// .map(|vote| {
// let data = match vote.data {
// ProposalVote::Yay => "yay",
// ProposalVote::Nay => "nay",
// ProposalVote::Abstain => "abstain"
// };
// let is_validator = vote.is_validator();
// (
// vote.delegator,
// String::from(data),
// is_validator
// )
// })
// .collect();

let validator_votes: Vec<(Address, String, token::Amount)> =
Vec::from_iter(votes.validators_vote.iter().map(|(address, vote)| {
let vote = match vote {
Expand All @@ -507,9 +490,6 @@ impl Query {
(address.clone(), String::from(vote), voting_power)
}));

//let validator_voting_power: Vec<(Address, token::Amount)> =
// votes.validator_voting_power.into_iter().collect();

let delegator_votes: Vec<(Address, String, Vec<(Address, token::Amount)>)> =
Vec::from_iter(votes.delegators_vote.iter().map(|(address, vote)| {
let vote = match vote {
Expand All @@ -529,18 +509,6 @@ impl Query {
(address.clone(), String::from(vote), voting_power)
}));

//let validator_voting_power: Vec<(Address, Amount)> = Vec::from_iter(
// votes.validator_voting_power.iter().map(|(address, voting_power)| {
// let vote = match vote {
// TallyVote::OnChain(ProposalVote::Yay) => "yay",
// TallyVote::OnChain(ProposalVote::Nay) => "nay",
// TallyVote::OnChain(ProposalVote::Abstain) => "abstain",
// TallyVote::Offline(_) => panic!("received offline tally")
// };
// (address.clone(), String::from(vote))
// })
//);

to_js_result((validator_votes, delegator_votes))
}

Expand Down Expand Up @@ -587,78 +555,6 @@ impl Query {
Ok(Uint8Array::from(code.as_slice()))
}

///// Returns a list of all proposals
//pub async fn query_proposals(&self) -> Result<Uint8Array, JsError> {
// let last_proposal_id_key = governance_storage::get_counter_key();
// let last_proposal_id =
// query_storage_value::<HttpClient, u64>(&self.client, &last_proposal_id_key)
// .await
// .unwrap();

// let from_id = if last_proposal_id > 10 {
// last_proposal_id - 10
// } else {
// 0
// };

// let mut proposals: Vec<ProposalInfo> = vec![];
// let epoch = RPC.shell().epoch(&self.client).await?;

// for id in from_id..last_proposal_id {
// let proposal = query_proposal_by_id(&self.client, id)
// .await
// .unwrap()
// .expect("Proposal should be written to storage.");
// let votes = compute_proposal_votes(&self.client, id, proposal.voting_end_epoch).await;
// let total_voting_power =
// get_total_staked_tokens(&self.client, proposal.voting_end_epoch)
// .await
// .unwrap();
// //TODO: for now we assume that interface does not support steward accounts
// let tally_type = proposal.get_tally_type(false);

// let proposal_type = match proposal.r#type {
// ProposalType::PGFSteward(_) => "pgf_steward",
// ProposalType::PGFPayment(_) => "pgf_payment",
// ProposalType::Default(_) => "default",
// };
// let status =
// if proposal.voting_start_epoch <= epoch && proposal.voting_end_epoch >= epoch {
// "ongoing"
// } else if proposal.voting_end_epoch < epoch {
// "finished"
// } else {
// "upcoming"
// };

// let content = serde_json::to_string(&proposal.content)?;

// let proposal_result = compute_proposal_result(votes, total_voting_power, tally_type);

// let proposal_info = ProposalInfo {
// id: proposal.id.to_string(),
// proposal_type: proposal_type.to_string(),
// author: proposal.author.to_string(),
// start_epoch: proposal.voting_start_epoch.0,
// end_epoch: proposal.voting_end_epoch.0,
// grace_epoch: proposal.grace_epoch.0,
// content,
// status: status.to_string(),
// result: proposal_result.result.to_string(),
// total_voting_power: proposal_result.total_voting_power.to_string_native(),
// total_yay_power: proposal_result.total_yay_power.to_string_native(),
// total_nay_power: proposal_result.total_nay_power.to_string_native(),
// };

// proposals.push(proposal_info);
// }

// let mut writer = vec![];
// BorshSerialize::serialize(&proposals, &mut writer)?;

// Ok(Uint8Array::from(writer.as_slice()))
//}

/// Returns a list of all delegations for given addresses and epoch
///
/// # Arguments
Expand Down
21 changes: 12 additions & 9 deletions packages/shared/lib/src/sdk/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{path::PathBuf, str::FromStr};

use namada::core::borsh::{BorshDeserialize, BorshSerialize};
use namada::core::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada::ibc::IbcShieldingData;
use namada::tendermint_rpc;
use namada::tx::data::GasLimit;
use namada::{
Expand Down Expand Up @@ -340,10 +341,7 @@ pub struct ClaimRewardsMsg {

impl ClaimRewardsMsg {
pub fn new(validator: String, source: Option<String>) -> ClaimRewardsMsg {
ClaimRewardsMsg {
validator,
source,
}
ClaimRewardsMsg { validator, source }
}
}

Expand All @@ -364,10 +362,7 @@ pub fn claim_rewards_tx_args(
) -> Result<args::ClaimRewards, JsError> {
let claim_rewards_msg = ClaimRewardsMsg::try_from_slice(claim_rewards_msg)?;

let ClaimRewardsMsg {
validator,
source,
} = claim_rewards_msg;
let ClaimRewardsMsg { validator, source } = claim_rewards_msg;
let tx = tx_msg_into_args(tx_msg)?;

let validator_address = Address::from_str(&validator)?;
Expand Down Expand Up @@ -497,6 +492,7 @@ pub struct IbcTransferMsg {
timeout_height: Option<u64>,
timeout_sec_offset: Option<u64>,
memo: Option<String>,
shielding_data: Option<Vec<u8>>,
}

/// Maps serialized tx_msg into IbcTransferTx args.
Expand Down Expand Up @@ -525,6 +521,7 @@ pub fn ibc_transfer_tx_args(
timeout_height,
timeout_sec_offset,
memo,
shielding_data,
} = ibc_transfer_msg;

let source_address = Address::from_str(&source)?;
Expand All @@ -534,11 +531,17 @@ pub fn ibc_transfer_tx_args(
let amount = InputAmount::Unvalidated(denom_amount);
let port_id = PortId::from_str(&port_id).expect("Port id to be valid");
let channel_id = ChannelId::from_str(&channel_id).expect("Channel id to be valid");
let ibc_shielding_data = match shielding_data {
Some(v) => Some(IbcShieldingData::try_from_slice(&v)?),
None => None,
};

Copy link
Collaborator Author

@jurevans jurevans Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/anoma/namada/blob/9b8252e6c3dd73678c00495b474bb7795a77b6c6/crates/ibc/src/msg.rs#L130-L137

We will need to implement something for MaspTransaction for shielding over IBC. Our schema can just handle the Borsh-serialized bytes, but that will need to be constructed in the interface, this just gets our schema up-to-date for IBC

let tx = tx_msg_into_args(tx_msg)?;

let args = args::TxIbcTransfer {
tx,
memo,
ibc_memo: memo,
ibc_shielding_data,
source,
receiver,
token,
Expand Down
6 changes: 3 additions & 3 deletions packages/types/docs/classes/BatchTxResultMsgValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#### Defined in

[tx/schema/batchTxResult.ts:12](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/batchTxResult.ts#L12)
[tx/schema/batchTxResult.ts:12](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/batchTxResult.ts#L12)

## Properties

Expand All @@ -41,7 +41,7 @@

#### Defined in

[tx/schema/batchTxResult.ts:7](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/batchTxResult.ts#L7)
[tx/schema/batchTxResult.ts:7](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/batchTxResult.ts#L7)

___

Expand All @@ -51,4 +51,4 @@ ___

#### Defined in

[tx/schema/batchTxResult.ts:10](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/batchTxResult.ts#L10)
[tx/schema/batchTxResult.ts:10](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/batchTxResult.ts#L10)
8 changes: 4 additions & 4 deletions packages/types/docs/classes/BondMsgValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#### Defined in

[tx/schema/bond.ts:17](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/bond.ts#L17)
[tx/schema/bond.ts:17](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/bond.ts#L17)

## Properties

Expand All @@ -42,7 +42,7 @@

#### Defined in

[tx/schema/bond.ts:15](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/bond.ts#L15)
[tx/schema/bond.ts:15](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/bond.ts#L15)

___

Expand All @@ -52,7 +52,7 @@ ___

#### Defined in

[tx/schema/bond.ts:9](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/bond.ts#L9)
[tx/schema/bond.ts:9](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/bond.ts#L9)

___

Expand All @@ -62,4 +62,4 @@ ___

#### Defined in

[tx/schema/bond.ts:12](https://github.com/anoma/namada-interface/blob/8d368aaf/packages/types/src/tx/schema/bond.ts#L12)
[tx/schema/bond.ts:12](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/bond.ts#L12)
54 changes: 54 additions & 0 deletions packages/types/docs/classes/ClaimRewardsMsgValue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[@namada/types](../README.md) / [Exports](../modules.md) / ClaimRewardsMsgValue

# Class: ClaimRewardsMsgValue

## Table of contents

### Constructors

- [constructor](ClaimRewardsMsgValue.md#constructor)

### Properties

- [source](ClaimRewardsMsgValue.md#source)
- [validator](ClaimRewardsMsgValue.md#validator)

## Constructors

### constructor

• **new ClaimRewardsMsgValue**(`data`): [`ClaimRewardsMsgValue`](ClaimRewardsMsgValue.md)

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | [`ClaimRewardsMsgValue`](ClaimRewardsMsgValue.md) |

#### Returns

[`ClaimRewardsMsgValue`](ClaimRewardsMsgValue.md)

#### Defined in

[tx/schema/claimRewards.ts:12](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/claimRewards.ts#L12)

## Properties

### source

• `Optional` **source**: `string`

#### Defined in

[tx/schema/claimRewards.ts:10](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/claimRewards.ts#L10)

___

### validator

• **validator**: `string`

#### Defined in

[tx/schema/claimRewards.ts:7](https://github.com/anoma/namada-interface/blob/cebcdd13/packages/types/src/tx/schema/claimRewards.ts#L7)
Loading
Loading