Skip to content

Commit

Permalink
move contract to wrapped contract
Browse files Browse the repository at this point in the history
  • Loading branch information
irfianto committed Apr 24, 2021
1 parent 9bd7b2d commit 41d0ad9
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 14 deletions.
20 changes: 9 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
[package]
name = "paras-claim-rewards-contract"
version = "0.1.0"
name = "paras-claim-rewards-contract-wrapper"
version = "0.0.1"
authors = ["Paras"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
serde = { version = "*", features = ["derive"] }
serde_json = "*"
near-sdk = "3.1.0"
near-contract-standards = "3.1.0"
[dev-dependencies]
near-sdk = "=3.1.0"
near-sdk-sim = "=3.1.0"
paras-claim-rewards-contract = { path = "./paras-claim-rewards-contract" }

[profile.release]
codegen-units = 1
Expand All @@ -24,4 +20,6 @@ panic = "abort"
overflow-checks = true

[workspace]
members = []
members = [
"paras-claim-rewards-contract",
]
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
cd "`dirname $0`"
cargo build --all --target wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/*.wasm ./res/
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "1.0.0",
"description": "Paras claim rewards contract",
"scripts": {
"build": "cargo build --all --target wasm32-unknown-unknown --release",
"postbuild": "cp target/wasm32-unknown-unknown/release/paras_claim_rewards_contract.wasm ./res/",
"build": "./build.sh",
"test": "cargo test -- --nocapture --color always",
"deploy:contract:dev": "yarn build && NODE_ENV=testnet near dev-deploy --wasmFile ./res/paras_claim_rewards_contract.wasm",
"deploy:contract:testnet": "yarn build && NODE_ENV=testnet node deployContract.js",
Expand Down
14 changes: 14 additions & 0 deletions paras-claim-rewards-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "paras-claim-rewards-contract"
version = "0.1.0"
authors = ["Paras"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
serde = { version = "*", features = ["derive"] }
serde_json = "*"
near-sdk = "3.1.0"
near-contract-standards = "3.1.0"
6 changes: 5 additions & 1 deletion src/lib.rs → paras-claim-rewards-contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{env, near_bindgen, AccountId, PanicOnDefault, assert_one_yocto, Promise};
use near_sdk::{env, near_bindgen, AccountId, PanicOnDefault, assert_one_yocto, Promise, log};
use near_sdk::json_types::{ValidAccountId, U128};
use near_sdk::collections::{LookupMap};
use near_contract_standards::upgrade::Ownable;
Expand Down Expand Up @@ -77,9 +77,11 @@ impl Contract{
let amount: u128 = amount.into();
assert!(amount <= current_amount, "ERR_AMOUNT_TOO_HIGH");

log!("Claiming reward : {} PARAS", (amount as f64 / 1e24));
current_rewards.internal_set_reward_amount(current_amount.checked_sub(amount).expect("ERR_INTEGER_OVERFLOW"));

self.records.insert(&env::predecessor_account_id(), &current_rewards);

ext_fungible_token::ft_transfer(
env::predecessor_account_id().into(),
amount.into(),
Expand Down Expand Up @@ -108,6 +110,8 @@ impl Contract{
current_rewards.internal_set_reward_amount(current_amount.checked_add(amount.into()).expect("ERR_INTEGER_OVERFLOW"));
self.records.insert(account_id.as_ref(), &current_rewards);

log!("Current reward for {} : {} PARAS", account_id.to_string(), current_rewards.internal_reward_amount() as f64 / 1e24);

}

/*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed res/status_message.wasm
Binary file not shown.

0 comments on commit 41d0ad9

Please sign in to comment.