-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ganesh oli
committed
Dec 7, 2022
1 parent
45af16b
commit 03d20f1
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore build artifacts from the local tests sub-crate. | ||
/target/ | ||
|
||
# Ignore backup files creates by cargo fmt. | ||
**/*.rs.bk | ||
|
||
# Remove Cargo.lock when creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "escrow" | ||
version = "0.1.0" | ||
authors = ["[your_name] <[your_email]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ink_primitives = { version = "3.3", default-features = false } | ||
ink_metadata = { version = "3.3", default-features = false, features = ["derive"], optional = true } | ||
ink_env = { version = "3.3", default-features = false } | ||
ink_storage = { version = "3.3", default-features = false } | ||
ink_lang = { version = "3.3", default-features = false } | ||
|
||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } | ||
|
||
[lib] | ||
name = "escrow" | ||
path = "lib.rs" | ||
crate-type = [ | ||
# Used for normal contract Wasm blobs. | ||
"cdylib", | ||
] | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink_metadata/std", | ||
"ink_env/std", | ||
"ink_storage/std", | ||
"ink_primitives/std", | ||
"scale/std", | ||
"scale-info/std", | ||
] | ||
ink-as-dependency = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use ink_lang as ink; | ||
|
||
#[ink::contract] | ||
mod escrow { | ||
|
||
|
||
#[ink(storage)] | ||
pub struct Escrow { | ||
payer: AccountId, | ||
payee: AccountId, | ||
lawyer: AccountId, | ||
amount: u128, | ||
} | ||
|
||
impl Escrow { | ||
#[ink(constructor)] | ||
pub fn new(payer: AccountId, payee: AccountId, amount: u128) -> Self { | ||
let caller = Self::env().caller(); | ||
Self { | ||
payer, | ||
payee, | ||
lawyer: caller, | ||
amount | ||
} | ||
} | ||
|
||
#[ink(message, payable)] | ||
pub fn deposit(&mut self) { | ||
assert!(self.env().caller() == self.payer, "Sender must be the payer"); | ||
assert!(self.env().balance() <= self.amount, "Can't send more than escrow amount"); | ||
} | ||
|
||
#[ink(message)] | ||
pub fn release(&mut self){ | ||
assert!(self.env().balance() == self.amount, "can't release fund before full amount is sent"); | ||
assert!(self.env().caller() == self.lawyer, "Only lawyer can release fund"); | ||
self.env().transfer(self.payee, self.amount).unwrap_err(); | ||
} | ||
|
||
#[ink(message)] | ||
pub fn balance_of(&self) -> u128 { | ||
self.env().balance() | ||
} | ||
} | ||
} |