Finish with executing contract for pool send

This commit is contained in:
Bogdan-Ștefan Neacșu
2022-03-02 17:50:47 +02:00
parent e27a2ae857
commit e7c8de8eec
8 changed files with 36 additions and 6 deletions
Generated
+1
View File
@@ -79,6 +79,7 @@ dependencies = [
"bandwidth-claim-contract",
"bip39",
"coconut-interface",
"cosmwasm-std",
"credentials",
"cw3-flex-multisig",
"network-defaults",
@@ -16,6 +16,7 @@ tauri-build = { version = "1.0.0-beta.2" }
[dependencies]
cw3-flex-multisig = "0.12.1"
cosmwasm-std = "1.0.0-beta5"
bip39 = "1.0.1"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
+8 -3
View File
@@ -4,6 +4,7 @@
)]
use bip39::Mnemonic;
use cosmwasm_std::{to_binary, CosmosMsg, WasmMsg};
use std::str::FromStr;
use std::sync::Arc;
@@ -71,7 +72,7 @@ async fn deposit_funds(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<St
nymd_url.as_ref(),
None,
None,
AccountId::from_str("nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr").ok(),
AccountId::from_str("nymt1sthrn5ep8ls5vzz8f9gp89khhmedahhdqdmmps").ok(),
mnemonic,
None,
)
@@ -207,7 +208,7 @@ async fn verify_credential(
nymd_url.as_ref(),
None,
None,
AccountId::from_str("nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr").ok(),
AccountId::from_str("nymt1sthrn5ep8ls5vzz8f9gp89khhmedahhdqdmmps").ok(),
mnemonic,
None,
)
@@ -215,7 +216,11 @@ async fn verify_credential(
let req = cw3_flex_multisig::msg::ExecuteMsg::Propose {
title: "Spend coconut".to_string(),
description: "Propose to spend a coconut cred".to_string(),
msgs: vec![],
msgs: vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: "nymt1sthrn5ep8ls5vzz8f9gp89khhmedahhdqdmmps".to_string(),
msg: to_binary(&ExecuteMsg::SpendCredential { amount: 1000000u64 }).unwrap(),
funds: vec![],
})],
latest: None,
};
let tx = nymd_client
@@ -15,6 +15,7 @@ pub struct InstantiateMsg {}
pub enum ExecuteMsg {
LinkPayment { data: LinkPaymentData },
BuyBandwidth {},
SpendCredential { amount: u64 },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
+3
View File
@@ -35,4 +35,7 @@ pub enum ContractError {
#[error("Wrong coin denomination, you must send {}", DENOM)]
WrongDenom,
#[error("The sender is not authorized to perform this action")]
Unauthorized,
}
+3
View File
@@ -40,6 +40,9 @@ pub fn execute(
match msg {
ExecuteMsg::LinkPayment { data } => transactions::link_payment(deps, env, info, data),
ExecuteMsg::BuyBandwidth {} => transactions::buy_bandwidth(deps, env, info),
ExecuteMsg::SpendCredential { amount } => {
transactions::spend_credential(deps, env, info, amount)
}
}
}
+17 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use cosmwasm_std::{DepsMut, Env, Event, MessageInfo, Response};
use cosmwasm_std::{Addr, BankMsg, Coin, DepsMut, Env, Event, MessageInfo, Response};
use crate::error::ContractError;
use crate::storage::{coconut, payments, status, Status};
@@ -67,6 +67,22 @@ pub(crate) fn buy_bandwidth(
Ok(Response::new().add_event(event))
}
pub(crate) fn spend_credential(
_deps: DepsMut<'_>,
_env: Env,
info: MessageInfo,
amount: u64,
) -> Result<Response, ContractError> {
if info.sender != Addr::unchecked(String::from("nymt1qwlgtx52gsdu7dtp0cekka5zehdl0uj3vqx3jd")) {
return Err(ContractError::Unauthorized);
}
let return_tokens = BankMsg::Send {
to_address: String::from("nymt1t6p4dl8nnlftvehz3jsklrd0aw458p4l6n9n4t"),
amount: vec![Coin::new(amount as u128, DENOM)],
};
Ok(Response::new().add_message(return_tokens))
}
#[cfg(test)]
mod tests {
use super::*;
+2 -2
View File
@@ -88,7 +88,7 @@ pub async fn post_blind_sign(
nymd_url.as_ref(),
None,
None,
AccountId::from_str("nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr").ok(),
None,
mnemonic,
None,
)
@@ -170,7 +170,7 @@ pub async fn post_verify_credential(
nymd_url.as_ref(),
None,
None,
AccountId::from_str("nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr").ok(),
None,
mnemonic,
None,
)