ΠΡΠ΅ΠΌ ΠΏΡΠΈΠ²Π΅Ρ!
Π
ΠΠ°Π²Π°ΠΉΡΠ΅ ΡΠ΅ΠΉΡΠ°Ρ Π½Π΅ΠΌΠ½ΠΎΠ³ΠΎ ΠΏΠΎΡΠ΅ΡΡΠΈΡΡΠ΅ΠΌ ΡΠ°Π·ΠΎΠ±ΡΠ°Π½ΡΠΉ
ΠΡΠ°ΠΏ 3. Π’Π΅ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ dApp Π°ΠΊΠΊΠ°ΡΠ½ΡΠ°
ΠΠ°ΠΊΠΈΠ΅ ΠΏΡΠΎΠ±Π»Π΅ΠΌΡ ΡΡΠ°Π·Ρ Π±ΡΠΎΡΠ°ΡΡΡΡ Π½Π° Π³Π»Π°ΡΠ° Ρ Alice dApp Account?
ΠΠΎ-ΠΏΠ΅ΡΠ²ΡΡ :
Boob ΠΈ Cooper ΠΌΠΎΠ³ΡΡ ΡΠ»ΡΡΠ°ΠΉΠ½ΠΎ ΠΎΡΠΏΡΠ°Π²ΠΈΡΡ Π½Π° Π°Π΄ΡΠ΅Ρ dApp ΡΡΠ΅Π΄ΡΡΠ²Π° Ρ ΠΏΠΎΠΌΠΎΡΡΡ ΠΎΠ±ΡΡΠ½ΠΎΠΉ transfer ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΠΈ ΠΈ, ΡΠ°ΠΊΠΈΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ, Π½Π΅ ΡΠΌΠΎΠ³ΡΡ ΠΏΠΎΠ»ΡΡΠΈΡΡ ΠΊ Π½ΠΈΠΌ Π΄ΠΎΡΡΡΠΏ ΠΎΠ±ΡΠ°ΡΠ½ΠΎ.ΠΠΎ-Π²ΡΠΎΡΡΡ :
ΠΡ Π½ΠΈΠΊΠ°ΠΊ Π½Π΅ ΠΎΠ³ΡΠ°Π½ΠΈΡΠΈΠ²Π°Π΅ΠΌ Alice Π² Π²ΡΠ²ΠΎΠ΄Π΅ ΡΡΠ΅Π΄ΡΡΠ² Π±Π΅Π· ΡΠΎΠ³Π»Π°ΡΠΎΠ²Π°Π½ΠΈΡ Ρ Boob ΠΈΠ»ΠΈ(ΠΈ) Cooper. Π’Π°ΠΊ ΠΊΠ°ΠΊ, ΠΎΠ±ΡΠ°ΡΠΈΡΠ΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅ Π½Π° verify, Π²ΡΠ΅ ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΠΈ ΠΎΡ Alice Π±ΡΠ΄ΡΡ ΠΈΡΠΏΠΎΠ»Π½ΡΡΡΡΡ.
ΠΠ°Π²Π°ΠΉΡΠ΅ ΠΈΡΠΏΡΠ°Π²ΠΈΠΌ 2-Π΅, Π·Π°ΠΏΡΠ΅ΡΠΈΠ² Alice transfer ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΠΈ. ΠΠ΅ΠΏΠ»ΠΎΠΈΠΌ ΠΈΡΠΏΡΠ°Π²Π»Π΅Π½Π½ΡΠΉ ΡΠΊΡΠΈΠΏΡ:
οΏΌ
ΠΡΠΎΠ±ΡΠ΅ΠΌ Π²ΡΠ²Π΅ΡΡΠΈ ΠΌΠΎΠ½Π΅ΡΡ Ρ dApp Alice ΠΈ Π΅Π΅ ΠΏΠΎΠ΄ΠΏΠΈΡΡΡ. ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΎΡΠΈΠ±ΠΊΡ:
ΠΡΠΎΠ±ΡΠ΅ΠΌ Π²ΡΠ²Π΅ΡΡΠΈ ΡΠ΅ΡΠ΅Π· withdraw:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 1000000}]}, payment: []}))
Π‘ΠΊΡΠΈΠΏΡ ΡΠ°Π±ΠΎΡΠ°Π΅Ρ ΠΈ ΡΠΎ 2-ΠΌ ΠΏΡΠ½ΠΊΡΠΎΠΌ ΠΌΡ ΡΠ°Π·ΠΎΠ±ΡΠ°Π»ΠΈΡΡ!
ΠΡΠ°ΠΏ 4. Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ DAO Ρ Π³ΠΎΠ»ΠΎΡΠΎΠ²Π°Π½ΠΈΠ΅ΠΌ
Π ΡΠΎΠΆΠ°Π»Π΅Π½ΠΈΡ, Π² ΡΠ·ΡΠΊΠ΅ RIDE ΠΏΠΎΠΊΠ° Π½Π΅ ΠΏΡΠ΅Π΄ΡΡΠΌΠΎΡΡΠ΅Π½Ρ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΠΈ ΡΠ°Π±ΠΎΡΡ Ρ ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΡΠΌΠΈ (ΡΠ»ΠΎΠ²Π°ΡΠΈ-ΡΠ»ΠΎΠ²Π°ΡΠ΅ΠΉ, ΠΈΡΠ΅ΡΠ°ΡΠΎΡΡ, ΡΠ΅Π΄ΡΡΡΠ΅ΡΡ ΠΈ ΠΏΡΠΎΡ). ΠΠ΄Π½Π°ΠΊΠΎ, Π΄Π»Ρ Π»ΡΠ±ΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ Ρ ΠΏΠ»ΠΎΡΠΊΠΈΠΌΠΈ ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΡΠΌΠΈ key-value ΠΌΡ ΠΌΠΎΠΆΠ΅ΠΌ ΡΠΏΡΠΎΠ΅ΠΊΡΠΈΡΠΎΠ²Π°ΡΡ ΡΠΈΡΡΠ΅ΠΌΡ ΡΠ°Π±ΠΎΡΡ ΡΠΎ ΡΡΡΠΎΠΊΠ°ΠΌΠΈ, ΡΠΎΠΎΡΠ²Π΅ΡΡΠ²Π΅Π½Π½ΠΎ Ρ ΠΊΠ»ΡΡΠ°ΠΌΠΈ ΠΈ ΠΈΡ ΡΠ°ΡΡΠΈΡΡΠΎΠ²ΠΊΠΎΠΉ.
Π‘ΡΡΠΎΠΊΠΈ ΠΎΡΠ΅Π½Ρ ΠΏΡΠΎΡΡΠΎ ΠΊΠΎΠ½ΠΊΠ°ΡΠ΅Π½ΠΈΡΠΎΠ²Π°ΡΡ, ΡΡΡΠΎΠΊΠΈ ΠΌΠΎΠΆΠ½ΠΎ ΡΠ°Π·Π΄Π΅Π»ΡΡΡ ΠΏΠΎ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΠΌ.
ΠΠ°Π²Π°ΠΉΡΠ΅ Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠ΅ΡΡΠΎΠ²ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° ΡΠΎΠ±Π΅ΡΠ΅ΠΌ ΠΈ ΡΠ°Π·Π±Π΅ΡΠ΅ΠΌ ΡΡΡΠΎΠΊΡ ΠΈ ΠΏΡΠΎΠ²Π΅ΡΠΈΠΌ ΠΊΠ°ΠΊ ΡΡΠΎ ΠΏΠΎΠ²Π»ΠΈΡΠ΅Ρ Π½Π° ΠΈΡΡ
ΠΎΠ΄ ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΠΈ.
ΠΡ ΠΎΡΡΠ°Π½ΠΎΠ²ΠΈΠ»ΠΈΡΡ Π½Π° ΡΠΎΠΌ, ΡΡΠΎ Alice Π½Π΅ ΠΌΠΎΠ³Π»Π° ΠΏΠΎΠ΄ΠΏΠΈΡΠ°ΡΡ Transfer ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΡ, ΡΠ°ΠΊ ΠΊΠ°ΠΊ ΡΡΠ° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ Π±ΡΠ»Π° Π·Π°Π±Π»ΠΎΠΊΠΈΡΠΎΠ²Π°Π½Π° Π² @verifier Π΄Π»Ρ ΡΠ°ΠΊΠΎΠ³ΠΎ ΡΠΈΠΏΠ° ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΠΉ.
ΠΠ°Π²Π°ΠΉΡΠ΅ ΠΏΠΎΡΠΏΡΠ°ΠΆΠ½ΡΠ΅ΠΌΡΡ ΡΠΎ ΡΡΡΠΎΠΊΠ°ΠΌΠΈ ΠΈ ΠΏΠΎΡΠΎΠΌ ΡΠ°Π·ΡΠ΅ΡΠΈΠΌ ΡΡΠΎ.
RIDE Strings
Π’ΡΠ°Π½Π·Π°ΠΊΡΠΈΡ ΡΠ½ΠΎΠ²Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Π°, ΠΌΡ ΡΠΌΠ΅Π΅ΠΌ ΡΠ°Π±ΠΎΡΠ°ΡΡ ΡΠΎ ΡΡΡΠΎΠΊΠ°ΠΌΠΈ.
οΏΌ
ΠΡΠΎΠ³ΠΎ, ΠΌΡ ΠΈΠΌΠ΅Π΅ΠΌ Π²ΡΠ΅ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎΠ΅ Π΄Π»Ρ Π½Π°ΠΏΠΈΡΠ°Π½ΠΈΡ ΡΠ»ΠΎΠΆΠ½ΠΎΠΉ Π»ΠΎΠ³ΠΈΠΊΠΈ DAO dApp.
Data Transactions
Data Transactions:
βThe maximum size for a key is 100 characters, and a key can contain arbitrary Unicode code points including spaces and other non-printable symbols. String values have a limit of 32,768 bytes and the maximum number of possible entries in data transaction is 100. Overall, the maximum size of a data transaction is around 140kbβββfor reference, almost exactly the length of Shakespeareβs play βRomeo and Julietβ.β
Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ DAO ΡΠΎ ΡΠ»Π΅Π΄ΡΡΡΠΈΠΌΠΈ ΡΡΠ»ΠΎΠ²ΠΈΡΠΌΠΈ:
ΠΠ»Ρ ΡΠΎΠ³ΠΎ, ΡΡΠΎΠ±Ρ ΡΡΠ°ΡΡΠ°ΠΏΡ ΠΏΠΎΠ»ΡΡΠΈΡΡ ΡΠΈΠ½Π°Π½ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅, Π²ΡΠ·Π²Π°Π² getFunds() Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠ° ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΠ° ΠΌΠΈΠ½ΠΈΠΌΡΠΌ 2-Ρ
ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΎΠ² β ΠΈΠ½Π²Π΅ΡΡΠΎΡΠΎΠ² DAO. ΠΡΠ²Π΅ΡΡΠΈ ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΠ΄Π΅Ρ ΡΠΎΠ²Π½ΠΎ ΡΡΠΎΠ»ΡΠΊΠΎ, ΡΠΊΠΎΠ»ΡΠΊΠΎ Π² ΡΡΠΌΠΌΠ΅ ΡΠΊΠ°Π·Π°Π»ΠΈ Π½Π° Π³ΠΎΠ»ΠΎΡΠΎΠ²Π°Π½ΠΈΠΈ Π²Π»Π°Π΄Π΅Π»ΡΡΡ DAO.
ΠΠ°Π²Π°ΠΉΡΠ΅ ΡΠ΄Π΅Π»Π°Π΅ΠΌ 3 ΡΠΈΠΏΠ° ΠΊΠ»ΡΡΠ΅ΠΉ ΠΈ Π΄ΠΎΠ±Π°Π²ΠΈΠΌ Π»ΠΎΠ³ΠΈΠΊΡ ΠΏΠΎ ΡΠ°Π±ΠΎΡΠ΅ Ρ Π±Π°Π»Π°Π½ΡΠ°ΠΌΠΈ Π² 2-Ρ Π½ΠΎΠ²ΡΡ ΡΡΠ½ΠΊΡΠΈΡΡ vote ΠΈ getFunds:
xx…xx_ia = ΠΈΠ½Π²Π΅ΡΡΠΎΡΡ, Π΄ΠΎΡΡΡΠΏΠ½ΡΠΉ Π±Π°Π»Π°Π½Ρ (vote, deposit, withdrawal)
xxβ¦xx_sv = ΡΡΠ°ΡΡΠ°ΠΏΡ, ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π³ΠΎΠ»ΠΎΡΠΎΠ² (vote, getFunds)
xxβ¦xx_sf = ΡΡΠ°ΡΡΠ°ΠΏΡ, ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π³ΠΎΠ»ΠΎΡΠΎΠ² (vote, getFunds)
xxβ¦xx = ΠΏΡΠ±Π»ΠΈΡΠ½ΡΠΉ Π°Π΄ΡΠ΅Ρ (35 ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ²)
ΠΠ°ΠΌΠ΅ΡΡΡΠ΅ Π² Vote Π½Π°ΠΌ ΠΏΠΎΠ½Π°Π΄ΠΎΠ±ΠΈΠ»ΠΎΡΡ ΠΎΠ±Π½ΠΎΠ²Π»ΡΡΡ ΡΡΠ°Π·Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΏΠΎΠ»Π΅ΠΉ:
WriteSet([DataEntry(key1, value1), DataEntry(key2, value2)]),
WriteSet ΠΏΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ Π½Π°ΠΌ Π΄Π΅Π»Π°ΡΡ ΡΡΠ°Π·Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ Π·Π°ΠΏΠΈΡΠ΅ΠΉ Π² ΡΠ°ΠΌΠΊΠ°Ρ ΠΎΠ΄Π½ΠΎΠΉ invokeScript ΡΡΠ°Π½Π·Π°ΠΊΡΠΈΠΈ.
ΠΠΎΡ ΡΠ°ΠΊ ΡΡΠΎ Π²ΡΠ³Π»ΡΠ΄ΠΈΡ Π² key-value Ρ
ΡΠ°Π½ΠΈΠ»ΠΈΡΠ΅ DAO dApp, ΠΏΠΎΡΠ»Π΅ ΡΠΎΠ³ΠΎ ΠΊΠ°ΠΊ Bob ΠΈ Cooper ΠΏΠΎΠΏΠΎΠ»Π½ΠΈΠ»ΠΈ ia-Π΄Π΅ΠΏΠΎΠ·ΠΈΡΡ:
Π€ΡΠ½ΠΊΡΠΈΡ Π΄Π΅ΠΏΠΎΠ·ΠΈΡΠ° Ρ Π½Π°Ρ ΡΠ»Π΅Π³ΠΊΠ° ΠΈΠ·ΠΌΠ΅Π½ΠΈΠ»Π°ΡΡ:
Π‘Π΅ΠΉΡΠ°Ρ Π½Π°ΡΡΡΠΏΠ°Π΅Ρ ΡΠ°ΠΌΡΠΉ Π²Π°ΠΆΠ½ΡΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ Π² Π΄Π΅ΡΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ DAO β Π³ΠΎΠ»ΠΎΡΠΎΠ²Π°Π½ΠΈΠ΅ Π·Π° ΠΏΡΠΎΠ΅ΠΊΡΡ Π΄Π»Ρ ΡΠΈΠ½Π°Π½ΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ.
Bob Π³ΠΎΠ»ΠΎΡΡΠ΅Ρ Π·Π° ΠΏΡΠΎΠ΅ΠΊΡ Neli Π½Π° 500000 wavelets:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"vote",args:[{type:"integer", value: 500000}, {type:"string", value: "3MrXEKJr9nDLNyVZ1d12Mq4jjeUYwxNjMsH"}]}, payment: []}))
Π Ρ
ΡΠ°Π½ΠΈΠ»ΠΈΡΠ΅ Π΄Π°Π½Π½ΡΡ
ΠΌΡ Π²ΠΈΠ΄ΠΈΠΌ Π²ΡΠ΅ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΡΠ΅ Π·Π°ΠΏΠΈΡΠΈ Π΄Π»Ρ Π°Π΄ΡΠ΅ΡΠ° Neli:
ΠΡΠΏΠ΅Ρ ΡΠ°ΠΊΠΆΠ΅ ΠΏΡΠΎΠ³ΠΎΠ»ΠΎΡΠΎΠ²Π°Π» Π·Π° ΠΏΡΠΎΠ΅ΠΊΡ Neli.
ΠΠ°Π²Π°ΠΉΡΠ΅ Π²Π·Π³Π»ΡΠ½Π΅ΠΌ Π½Π° ΠΊΠΎΠ΄ ΡΡΠ½ΠΊΡΠΈΠΈ getFunds. Neli Π΄ΠΎΠ»ΠΆΠ½Π° ΡΠΎΠ±ΡΠ°ΡΡ ΠΌΠΈΠ½ΠΈΠΌΡΠΌ 2 Π³ΠΎΠ»ΠΎΡΠ°, ΡΡΠΎΠ±Ρ ΠΈΠΌΠ΅ΡΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ Π²ΡΠ²Π΅ΡΡΠΈ ΡΡΠ΅Π΄ΡΡΠ²Π° ΠΈΠ· DAO.
Neli ΡΠΎΠ±ΠΈΡΠ°Π΅ΡΡΡ Π²ΡΠ²Π΅ΡΡΠΈ ΠΏΠΎΠ»ΠΎΠ²ΠΈΠ½Ρ Π΄ΠΎΠ²Π΅ΡΠ΅Π½Π½ΠΎΠΉ Π΅ΠΉ ΡΡΠΌΠΌΡ:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"getFunds",args:[{type:"integer", value: 500000}]}, payment: []}))
ΠΠΉ ΡΡΠΎ ΡΠ΄Π°Π΅ΡΡΡ, ΡΠΎ Π΅ΡΡΡ DAO ΡΠ°Π±ΠΎΡΠ°Π΅Ρ!
ΠΡ ΡΠ°ΡΡΠΌΠΎΡΡΠ΅Π»ΠΈ ΠΏΡΠΎΡΠ΅ΡΡ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ DAO Π½Π° ΡΠ·ΡΠΊΠ΅ RIDE4DAPPS.
Π ΡΠ»Π΅Π΄ΡΡΡΠΈΡ
ΡΠ°ΡΡΡΡ
ΠΌΡ ΠΏΠΎΠ΄ΡΠΎΠ±Π½Π΅Π΅ Π·Π°ΠΉΠΌΠ΅ΠΌΡΡ ΡΠ΅ΡΠ°ΠΊΡΠΎΡΠΈΠ½Π³ΠΎΠΌ ΠΊΠΎΠ΄Π° ΠΈ ΡΠ΅ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ΠΌ ΠΊΠ΅ΠΉΡΠΎΠ².
ΠΠΎΠ»Π½Π°Ρ Π²Π΅ΡΡΠΈΡ ΠΊΠΎΠ΄Π° Π²
# In this example multiple accounts can deposit their funds to DAO and safely take them back, no one can interfere with this.
# DAO participants can also vote for particular addresses and let them withdraw invested funds then quorum has reached.
# An inner state is maintained as mapping `address=>waves`.
# https://medium.com/waves-lab/waves-announces-funding-for-ride-for-dapps-developers-f724095fdbe1
# You can try this contract by following commands in the IDE (ide.wavesplatform.com)
# Run commands as listed below
# From account #0:
# deploy()
# From account #1: deposit funds
# broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 100000000, asset:null }]}))
# From account #2: deposit funds
# broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 100000000, asset:null }]}))
# From account #1: vote for startup
# broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"vote",args:[{type:"integer", value: 500000}, {type:"string", value: "3MrXEKJr9nDLNyVZ1d12Mq4jjeUYwxNjMsH"}]}, payment: []}))
# From account #2: vote for startup
# broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"vote",args:[{type:"integer", value: 500000}, {type:"string", value: "3MrXEKJr9nDLNyVZ1d12Mq4jjeUYwxNjMsH"}]}, payment: []}))
# From account #3: get invested funds
# broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"getFunds",args:[{type:"integer", value: 500000}]}, payment: []}))
{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
@Callable(i)
func deposit() = {
let pmt = extract(i.payment)
if (isDefined(pmt.assetId)) then throw("can hodl waves only at the moment")
else {
let currentKey = toBase58String(i.caller.bytes)
let xxxInvestorBalance = currentKey + "_" + "ib"
let currentAmount = match getInteger(this, xxxInvestorBalance) {
case a:Int => a
case _ => 0
}
let newAmount = currentAmount + pmt.amount
WriteSet([DataEntry(xxxInvestorBalance, newAmount)])
}
}
@Callable(i)
func withdraw(amount: Int) = {
let currentKey = toBase58String(i.caller.bytes)
let xxxInvestorBalance = currentKey + "_" + "ib"
let currentAmount = match getInteger(this, xxxInvestorBalance) {
case a:Int => a
case _ => 0
}
let newAmount = currentAmount - amount
if (amount < 0)
then throw("Can't withdraw negative amount")
else if (newAmount < 0)
then throw("Not enough balance")
else ScriptResult(
WriteSet([DataEntry(xxxInvestorBalance, newAmount)]),
TransferSet([ScriptTransfer(i.caller, amount, unit)])
)
}
@Callable(i)
func getFunds(amount: Int) = {
let quorum = 2
let currentKey = toBase58String(i.caller.bytes)
let xxxStartupFund = currentKey + "_" + "sf"
let xxxStartupVotes = currentKey + "_" + "sv"
let currentAmount = match getInteger(this, xxxStartupFund) {
case a:Int => a
case _ => 0
}
let totalVotes = match getInteger(this, xxxStartupVotes) {
case a:Int => a
case _ => 0
}
let newAmount = currentAmount - amount
if (amount < 0)
then throw("Can't withdraw negative amount")
else if (newAmount < 0)
then throw("Not enough balance")
else if (totalVotes < quorum)
then throw("Not enough votes. At least 2 votes required!")
else ScriptResult(
WriteSet([
DataEntry(xxxStartupFund, newAmount)
]),
TransferSet([ScriptTransfer(i.caller, amount, unit)])
)
}
@Callable(i)
func vote(amount: Int, address: String) = {
let currentKey = toBase58String(i.caller.bytes)
let xxxInvestorBalance = currentKey + "_" + "ib"
let xxxStartupFund = address + "_" + "sf"
let xxxStartupVotes = address + "_" + "sv"
let currentAmount = match getInteger(this, xxxInvestorBalance) {
case a:Int => a
case _ => 0
}
let currentVotes = match getInteger(this, xxxStartupVotes) {
case a:Int => a
case _ => 0
}
let currentFund = match getInteger(this, xxxStartupFund) {
case a:Int => a
case _ => 0
}
if (amount <= 0)
then throw("Can't withdraw negative amount")
else if (amount > currentAmount)
then throw("Not enough balance")
else ScriptResult(
WriteSet([
DataEntry(xxxInvestorBalance, currentAmount - amount),
DataEntry(xxxStartupVotes, currentVotes + 1),
DataEntry(xxxStartupFund, currentFund + amount)
]),
TransferSet([ScriptTransfer(i.caller, amount, unit)])
)
}
@Verifier(tx)
func verify() = {
match tx {
case t: TransferTransaction =>false
case _ => true
}
}
ΠΡΡΠΎΡΠ½ΠΈΠΊ: habr.com