From b67a7b0f6d103cce97d4b9fe539dce4157320705 Mon Sep 17 00:00:00 2001 From: Conor Gallagher <72916734+AE-0h@users.noreply.github.com> Date: Sat, 19 Mar 2022 09:34:49 -0400 Subject: [PATCH] Add files via upload Charge contract --- contracts/aerx_profile_nft/src/charge.rs | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 contracts/aerx_profile_nft/src/charge.rs diff --git a/contracts/aerx_profile_nft/src/charge.rs b/contracts/aerx_profile_nft/src/charge.rs new file mode 100644 index 0000000..1032f5f --- /dev/null +++ b/contracts/aerx_profile_nft/src/charge.rs @@ -0,0 +1,59 @@ +//this is a contract I formed from a venmo clone I found online. +//for front-end this should be linked up to the charge button and open a prompt window. +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::collections::{LookupMap}; +use near_sdk::{env, setup_alloc, near_bindgen, AccountId, Promise}; + +setup_alloc!(); + + +#[near_bindgen] +#[derive(BorshDeserialize, BorshSerialize)] +pub struct Charge{ + memo: LookupMap> +} +//giving us our default value or balance to fallback on +impl Default for Charge { + fn default() -> Self { + Self{ + memo: LookupMap::new(b"memo".to_vec()) + } + } +} + +#[near_bindgen] +impl Charge{ + ///adding memo and price functionallity + pub fn add_memo(&mut self, memo_text: String, price:String){ + + let account_id=env::signer_account_id(); + let contains_user=self.memo.contains_key(&account_id); + + if contains_user{ + let mut temp_list=match self.memo.get(&account_id){ + Some(x)=>x, // x is vector of memos + None=>vec![] //else this will return an empty vector + }; + + temp_list.push(memo_text + " || " + &price + "Aerx"); + self.memo.insert(&account_id, &temp_list); + + }else{ + let fresh_vec=vec![memo_text + " || " + &price+ "Aerx"]; + self.memo.insert(&account_id, &fresh_vec); + } + } + //transfer function + pub fn transfer_money(&mut self, account_id: AccountId, amount:f64){ + Promise::new(account_id).transfer(amount as u128); + } + + //View Methods + pub fn get_memos(self, user:String) -> Vec{ + match self.memo.get(&user){ + Some(x)=>x, // vector that contains all memos + None=>vec![] //else this will return an empty vector + } + } +} +