
ආයුබෝවන් හැමෝටම!
В මෙම කොටසේදී අපි dApp (විමධ්යගත යෙදුමක්) නිර්මාණය කර වැඩ කරන්නේ කෙසේද යන්න විස්තරාත්මකව සොයා බැලුවෙමු. .
දැන් අපි විසුරුවා හරින ලද එක ටිකක් පරීක්ෂා කර බලමු. .
පියවර 3: dApp ගිණුම පරීක්ෂා කිරීම

ඇලිස් සමඟ ඔබේ ඇසට වහාම හසු වන ගැටළු මොනවාද? dApp ගිණුම?
පළමුව:
බූබ් සහ කූපර් අහම්බෙන් නිතිපතා ගිණුමක් භාවිතයෙන් dApp ලිපිනයකට අරමුදල් යැවිය හැකිය. මාරු කිරීම ගනුදෙනු සහ එම නිසා ඒවාට නැවත ප්රවේශ වීමට නොහැකි වනු ඇත.දෙවනුව:
බූබ් හෝ කූපර්ගේ අනුමැතියකින් තොරව ඇලිස් අරමුදල් ආපසු ගැනීම අපි සීමා නොකරමු. ඔබට පෙනෙන පරිදි, ඇලිස් වෙතින් සියලුම ගනුදෙනු ක්රියාත්මක වනු ඇත.
ඇලිස්ව තහනම් කිරීමෙන් දෙවැන්න නිවැරදි කරමු. මාරු කිරීම ගනුදෙනු. නිවැරදි කළ ස්ක්රිප්ට් එක යෙදවීම:


අපි ඇලිස්ගේ 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 තත්
ගනුදෙනුව නැවතත් කළ හැකියි, අපි නූල් සමඟ වැඩ කරන්නේ කෙසේදැයි දනිමු.


ඉතින්, සංකීර්ණ තර්කනය ලිවීමට අවශ්ය සියල්ල අප සතුව ඇත. DAO dApp.
දත්ත ගනුදෙනු
දත්ත ගනුදෙනු:
"යතුරක් සඳහා උපරිම ප්රමාණය අක්ෂර 100 ක් වන අතර, යතුරක හිස්තැන් සහ අනෙකුත් මුද්රණය කළ නොහැකි සංකේත ඇතුළුව අත්තනෝමතික යුනිකෝඩ් කේත ලක්ෂ්ය අඩංගු විය හැක. තන්තු අගයන්ට බයිට් 32,768 ක සීමාවක් ඇති අතර දත්ත ගනුදෙනුවේ ඇතුළත් කළ හැකි උපරිම සංඛ්යාව 100 කි. සමස්තයක් වශයෙන්, දත්ත ගනුදෙනුවක උපරිම ප්රමාණය 140kb පමණ වේ - යොමුව සඳහා, ෂේක්ස්පියර්ගේ 'රෝමියෝ සහ ජුලියට්' නාට්යයේ දිග හරියටම සමාන වේ."
අපි පහත කොන්දේසි සහිතව DAO එකක් නිර්මාණය කරමු:
ආරම්භක ව්යාපාරයකට ඇමතීමෙන් අරමුදල් ලබා ගැනීම සඳහා අරමුදල් ලබා ගන්න() අවම වශයෙන් සහභාගිවන්නන් දෙදෙනෙකුගේ - DAO ආයෝජකයින්ගේ - සහාය අවශ්ය වේ. ඉවත් කරන්න දක්වා ඇති මුළු එකතුවට සමාන ප්රමාණයක් තිබිය හැකිය ඡන්දය දීම DAO හිමිකරුවන්.
අපි යතුරු වර්ග 3ක් නිර්මාණය කර නව කාර්යයන් 2ක ශේෂයන් සමඟ වැඩ කිරීම සඳහා තර්කනය එකතු කරමු, ඡන්දය දෙන්න සහ අරමුදල් ලබා ගන්න:
xx...xx_අයියා = ආයෝජකයින්, පවතින ශේෂය (ඡන්දය, තැන්පත් කිරීම, ආපසු ගැනීම)
xx...xx_එස්වී = ආරම්භක ව්යාපාර, ඡන්ද ගණන (ඡන්දය දෙන්න, අරමුදල් ලබා ගන්න)
xx...xx_sf_ = ආරම්භක ව්යාපාර, ඡන්ද ගණන (ඡන්දය දෙන්න, අරමුදල් ලබා ගන්න)
xx…xx = පොදු ලිපිනය (අක්ෂර 35)
Vote හි අපට එකවර ක්ෂේත්ර කිහිපයක් යාවත්කාලීන කිරීමට අවශ්ය වූ බව සලකන්න:
WriteSet([DataEntry(key1, value1), DataEntry(key2, value2)]),WriteSet එකකින් අපට එකවර වාර්තා කිහිපයක් සෑදීමට ඉඩ සලසයි. ඉන්වෝක්ස්ක්රිප්ට් ගනුදෙනු.
බොබ් සහ කූපර් නැවත පිරවූ පසු 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: []}))
දත්ත ගබඩාවේ, නෙලිගේ ලිපිනය සඳහා අවශ්ය සියලුම වාර්තා අපට පෙනේ:

කූපර් ද නෙලි ව්යාපෘතියට ඡන්දය දුන්නේය.

අපි ශ්රිත කේතය දෙස බලමු. අරමුදල් ලබා ගන්නDAO වෙතින් අරමුදල් ලබා ගැනීමට හැකි වීම සඳහා නෙලි අවම වශයෙන් ඡන්ද 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
