You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
// Pseudo staking contract for the tests |
|
import "./messages"; |
|
|
|
contract PseudoStaking { |
|
stakes: map[Address]Int; |
|
init() {} |
|
|
|
receive("Deposit") { |
|
let ctx: Context = context(); |
|
let sender: Address = ctx.sender; |
|
let ex_stake: Int? = self.stakes.get(sender); |
|
if (ex_stake == null) { |
|
ex_stake = 0; |
|
} |
|
self.stakes.set(sender, ex_stake!! + ctx.value); |
|
} |
|
|
|
receive(msg: StakingWithdraw) { |
|
let ctx: Context = context(); |
|
let value: Int = msg.value; |
|
if (value == 0) { |
|
value = (self.stakes.get(ctx.sender)!! * 110) / 100; |
|
} |
|
self.stakes.set(ctx.sender, self.stakes.get(ctx.sender)!! - value); |
|
if (self.stakes.get(ctx.sender)!! < 0) { |
|
self.stakes.set(ctx.sender, 0); |
|
} |
|
send(SendParameters { |
|
value: value, |
|
to: ctx.sender, |
|
body: "Withdraw completed".asComment() |
|
}); |
|
} |
|
|
|
receive(msg: Slice) { |
|
let op: Int = msg.loadUint(32); |
|
if (op == 0x7bcd1fef) { |
|
let ctx: Context = context(); |
|
let sender: Address = ctx.sender; |
|
let ex_stake: Int? = self.stakes.get(sender); |
|
if (ex_stake == null) { |
|
ex_stake = 0; |
|
} |
|
self.stakes.set(sender, ex_stake!! + ctx.value); |
|
} |
|
} |
|
}
|
|
|