Skip to content

Commit

Permalink
escrow contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganesh oli committed Dec 7, 2022
1 parent 45af16b commit 03d20f1
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
9 changes: 9 additions & 0 deletions escrow/.gitignore
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
35 changes: 35 additions & 0 deletions escrow/Cargo.toml
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 = []
47 changes: 47 additions & 0 deletions escrow/lib.rs
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()
}
}
}

0 comments on commit 03d20f1

Please sign in to comment.