ආයුබෝවන් හැමෝටම!
В
දැන් අපි විසුරුවා හරින ලද ඒවා ටිකක් පරීක්ෂා කරමු
අදියර 3. dApp ගිණුම පරීක්ෂා කිරීම
ඇලිස් සමඟ ඇති කටහඬට වහාම පැන නගින ගැටළු මොනවාද? dApp ගිණුම?
පළමුව:
Boob සහ Cooper අහම්බෙන් සාමාන්ය එකක් භාවිතයෙන් dApp ලිපිනයකට අරමුදල් යැවිය හැක මාරු කිරීම ගණුදෙණු කරන අතර ඒ අනුව නැවත ඒවාට ප්රවේශ වීමට නොහැකි වනු ඇත.දෙවනුව:
බූබ් සහ/හෝ කූපර්ගේ අනුමැතියකින් තොරව අරමුදල් ආපසු ගැනීමෙන් අපි කිසිම ආකාරයකින් ඇලිස්ට සීමා නොකරමු. සත්යාපනය කිරීමට අවධානය යොමු කරන්න, ඇලිස් වෙතින් සියලුම ගනුදෙනු ක්රියාත්මක වනු ඇත.
ඇලිස්ව තහනම් කරලා 2ක් හදමු මාරු කිරීම ගනුදෙනු. නිවැරදි කළ ස්ක්රිප්ට් යොදන්න:

අපි dApp ඇලිස් සහ ඇගේ අත්සන සහිත කාසි ආපසු ගැනීමට උත්සාහ කරමු. අපට දෝෂයක් ලැබේ:
Withdraw හරහා withdraw කිරීමට උත්සාහ කිරීම:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 1000000}]}, payment: []}))
පිටපත ක්රියාත්මක වන අතර අපි 2 වන කරුණ සොයා ගත්තෙමු!
අදියර 4. ඡන්දය සමඟ DAO එකක් සාදන්න
අවාසනාවකට, RIDE භාෂාව තවමත් එකතු කිරීම් (ශබ්දකෝෂ, ශබ්දකෝෂ, පුනරාවර්තක, අඩු කරන්නන්, ආදිය) සමඟ වැඩ කිරීමේ හැකියාව ලබා දී නැත. කෙසේ වෙතත්, පැතලි එකතු කිරීම් මත ඕනෑම මෙහෙයුම් සඳහා යතුරු අගය අපට යතුරු සහ ඒවායේ විකේතනය සමඟ පිළිවෙලින් නූල් සමඟ වැඩ කිරීම සඳහා පද්ධතියක් සැලසුම් කළ හැකිය.
නූල් සම්බන්ධ කිරීම ඉතා පහසුය, නූල් දර්ශක මගින් වෙන් කළ හැක.
අපි තන්තුව පරීක්ෂණ අවස්ථාවක් ලෙස එකතු කර විග්රහ කර ගනුදෙනුවේ ප්රතිඵලයට මෙය බලපාන්නේ කෙසේදැයි පරීක්ෂා කරමු.
මෙම ආකාරයේ ගනුදෙනු සඳහා @verifier හි මෙම හැකියාව අවහිර කර ඇති බැවින්, ඇලිස්ට මාරු කිරීමේ ගනුදෙනුව අත්සන් කළ නොහැකි බව අපි විසඳා ගත්තෙමු.
අපි නූල්වලින් පුහුණු වී පසුව මෙය විසඳා ගනිමු.
RIDE Strings
ගනුදෙනුව නැවත කළ හැකිය, අපි නූල් සමඟ වැඩ කරන්නේ කෙසේදැයි දනිමු.

සමස්තයක් වශයෙන්, ඔබට සංකීර්ණ තර්කනය ලිවීමට අවශ්ය සියල්ල අප සතුව ඇත DAO dApp.
දත්ත ගනුදෙනු
දත්ත ගනුදෙනු:
“යතුරක් සඳහා උපරිම ප්රමාණය අක්ෂර 100 ක් වන අතර යතුරක හිස්තැන් සහ මුද්රණය කළ නොහැකි වෙනත් සංකේත ඇතුළු අත්තනෝමතික යුනිකෝඩ් කේත ලකුණු අඩංගු විය හැක. තන්තු අගයන් බයිට් 32,768 ක සීමාවක් ඇති අතර දත්ත ගණුදෙණුවකදී හැකි උපරිම ඇතුළත් කිරීම් සංඛ්යාව 100 කි. සමස්තයක් ලෙස දත්ත ගනුදෙනුවක උපරිම ප්රමාණය 140kb පමණ වේ - යොමුව සඳහා, හරියටම ශේක්ස්පියර්ගේ 'රෝමියෝ සහ ජුලියට්' නාට්යයේ දිගට සමාන වේ. '."
අපි පහත කොන්දේසි සහිතව DAO එකක් සාදන්නෙමු:
ඇමතීමෙන් අරමුදල් ලබා ගැනීම සඳහා ආරම්භයක් සඳහා getFunds() අවම වශයෙන් සහභාගිවන්නන් 2 දෙනෙකුගේ සහාය - DAO ආයෝජකයින් අවශ්ය වේ. ඉවත් කරන්න එය දක්වා ඇති එකතුවට හරියටම හැකි වනු ඇත ඡන්දය DAO හිමිකරුවන්.
අපි යතුරු වර්ග 3 ක් සාදා නව කාර්යයන් 2 ක ශේෂයන් සමඟ වැඩ කිරීම සඳහා තර්කනය එකතු කරමු ඡන්දය සහ getFunds:
xx...xx_ia = ආයෝජකයින්, පවතින ශේෂය (ඡන්දය, තැන්පතු, මුදල් ආපසු ගැනීම)
xx...xx_sv = ආරම්භක, ඡන්ද සංඛ්යාව (ඡන්දය, ලබාගන්න අරමුදල්)
xx...xx_sf = ආරම්භක, ඡන්ද සංඛ්යාව (ඡන්දය, ලබාගන්න අරමුදල්)
xx...xx = පොදු ලිපිනය (අක්ෂර 35)
අපට එකවර ක්ෂේත්ර කිහිපයක් යාවත්කාලීන කිරීමට අවශ්ය වූ ඡන්දයේ දැනුම්දීම:
WriteSet([DataEntry(key1, value1), DataEntry(key2, value2)]),
WriteSet එක තුළ එකවර වාර්තා කිහිපයක් සෑදීමට අපට ඉඩ සලසයි invokeScript ගනුදෙනු.
බොබ් සහ කූපර් නැවත පිරවීමෙන් පසු DAO dApp හි ප්රධාන වටිනාකම් ගබඩාවේ පෙනෙන්නේ මෙයයි ia- තැන්පතු:
අපගේ තැන්පතු කාර්යය සුළු වශයෙන් වෙනස් වී ඇත:
DAO හි ක්රියාකාරකම්වල වැදගත්ම මොහොත දැන් පැමිණේ - ඡන්දය දෙන්න අරමුදල් සඳහා ව්යාපෘති සඳහා.
500000 තරංග මත නෙලි ව්යාපෘතිය සඳහා බොබ් ඡන්දය දෙයි:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"vote",args:[{type:"integer", value: 500000}, {type:"string", value: "3MrXEKJr9nDLNyVZ1d12Mq4jjeUYwxNjMsH"}]}, payment: []}))
දත්ත ගබඩාවේ, Neli ලිපිනය සඳහා අවශ්ය සියලුම ඇතුළත් කිරීම් අපි දකිමු:
කූපර් ද නෙලි ව්යාපෘතියට ඡන්දය දුන්නේය.
අපි කාර්යය කේතය දෙස බලමු getFunds. DAO වෙතින් අරමුදල් ආපසු ගැනීමට හැකි වීමට Neli අවම වශයෙන් ඡන්ද 2ක් එකතු කළ යුතුය.
නෙලී ඇයට භාර දුන් මුදලින් අඩක් ආපසු ගැනීමට යයි:
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
}
}
මූලාශ්රය: www.habr.com