அனைவருக்கும் வணக்கம்!
В
பிரிக்கப்பட்டதை இப்போது கொஞ்சம் சோதிப்போம்
நிலை 3. dApp கணக்கைச் சோதனை செய்தல்
ஆலிஸுடன் உடனடியாக என்ன பிரச்சனைகள் உங்களைத் தாக்குகின்றன? dApp கணக்கு?
முதலாவதாக:
Boob மற்றும் Cooper தற்செயலாக dApp முகவரிக்கு வழக்கமாகப் பயன்படுத்தி நிதியை அனுப்பலாம் பரிமாற்ற பரிவர்த்தனைகள் மற்றும் இதனால் அவற்றை மீண்டும் அணுக முடியாது.இரண்டாவதாக:
பூப் மற்றும்/அல்லது கூப்பரின் ஒப்புதல் இல்லாமல் ஆலிஸ் நிதியை திரும்பப் பெறுவதை நாங்கள் எந்த வகையிலும் கட்டுப்படுத்த மாட்டோம். சரிபார்ப்பதில் கவனம் செலுத்துங்கள், ஆலிஸின் அனைத்து பரிவர்த்தனைகளும் செயல்படுத்தப்படும்.
ஆலிஸை தடை செய்வதன் மூலம் 2வது சரிசெய்வோம் பரிமாற்ற பரிவர்த்தனைகள். சரி செய்யப்பட்ட ஸ்கிரிப்டை வரிசைப்படுத்துவோம்:

நாங்கள் dApp ஆலிஸ் மற்றும் அவரது கையொப்பத்திலிருந்து நாணயங்களை திரும்பப் பெற முயற்சிக்கிறோம். நாங்கள் ஒரு பிழையைப் பெறுகிறோம்:
திரும்பப் பெறுவதன் மூலம் திரும்பப் பெற முயற்சிப்போம்:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 1000000}]}, payment: []}))
ஸ்கிரிப்ட் வேலை செய்கிறது, நாங்கள் 2 வது புள்ளியைக் கண்டுபிடித்தோம்!
நிலை 4. வாக்களிப்புடன் ஒரு DAO ஐ உருவாக்கவும்
துரதிருஷ்டவசமாக, RIDE மொழி இன்னும் சேகரிப்புகளுடன் வேலை செய்யும் திறனை வழங்கவில்லை (அகராதி அகராதிகள், மீண்டும் செய்பவர்கள், குறைப்பவர்கள், முதலியன). இருப்பினும், பிளாட் சேகரிப்புகளுடன் கூடிய எந்த நடவடிக்கைகளுக்கும் விசை மதிப்பு விசைகள் மற்றும் அவற்றின் மறைகுறியாக்கத்துடன், சரங்களுடன் வேலை செய்வதற்கான ஒரு அமைப்பை நாம் வடிவமைக்க முடியும்.
சரங்களை இணைப்பது மிகவும் எளிதானது; சரங்களை குறியீடுகளால் பிரிக்கலாம்.
சோதனை உதாரணமாக ஒரு சரத்தை சேகரித்து அலசுவோம், மேலும் இது பரிவர்த்தனையின் முடிவை எவ்வாறு பாதிக்கிறது என்பதைச் சரிபார்க்கவும்.
இந்த வகையான பரிவர்த்தனைக்கு @verifier இல் இந்த திறன் தடுக்கப்பட்டதால், ஆலிஸால் பரிமாற்ற பரிவர்த்தனையில் கையொப்பமிட முடியவில்லை என்ற உண்மையை நாங்கள் தீர்த்துக் கொண்டோம்.
சரங்களைக் கொண்டு பயிற்சி செய்து பின்னர் இதைத் தீர்ப்போம்.
சவாரி சரங்கள்
பரிவர்த்தனை மீண்டும் சாத்தியமாகும், சரங்களுடன் எவ்வாறு வேலை செய்வது என்பது எங்களுக்குத் தெரியும்.

மொத்தத்தில், சிக்கலான தர்க்கத்தை எழுத தேவையான அனைத்தும் எங்களிடம் உள்ளன DAO dApp.
தரவு பரிவர்த்தனைகள்
தரவு பரிவர்த்தனைகள்:
"ஒரு விசையின் அதிகபட்ச அளவு 100 எழுத்துகள், மேலும் ஒரு விசையானது இடைவெளிகள் மற்றும் பிற அச்சிட முடியாத குறியீடுகள் உட்பட தன்னிச்சையான யூனிகோட் குறியீடு புள்ளிகளைக் கொண்டிருக்கலாம். சர மதிப்புகளின் வரம்பு 32,768 பைட்டுகள் மற்றும் தரவு பரிமாற்றத்தில் சாத்தியமான உள்ளீடுகளின் அதிகபட்ச எண்ணிக்கை 100 ஆகும். ஒட்டுமொத்தமாக, தரவு பரிமாற்றத்தின் அதிகபட்ச அளவு 140kb ஆகும் - குறிப்புக்கு, ஷேக்ஸ்பியரின் நாடகமான ரோமியோ ஜூலியட்டின் நீளம் கிட்டத்தட்ட சரியாக இருக்கும். '."
பின்வரும் நிபந்தனைகளுடன் ஒரு DAO ஐ உருவாக்குகிறோம்:
அழைப்பின் மூலம் ஒரு ஸ்டார்ட்அப் நிதியைப் பெறுவதற்காக getFunds() குறைந்தது 2 பங்கேற்பாளர்களின் ஆதரவு - DAO முதலீட்டாளர்கள் - தேவை. வாபஸ் மொத்தத்தில் சுட்டிக்காட்டப்பட்டதைப் போலவே இது சாத்தியமாகும் வாக்களிப்பது DAO உரிமையாளர்கள்.
3 வகையான விசைகளை உருவாக்கி, 2 புதிய செயல்பாடுகள் வாக்கு மற்றும் getFunds இல் இருப்புகளுடன் வேலை செய்வதற்கான தர்க்கத்தைச் சேர்ப்போம்:
xx...xx_ia = முதலீட்டாளர்கள், கிடைக்கும் இருப்பு (வாக்கு, வைப்பு, திரும்பப் பெறுதல்)
xx...xx_sv = தொடக்கங்கள், வாக்குகளின் எண்ணிக்கை (வாக்கு, பெறு நிதி)
xx...xx_எஸ் எப் = தொடக்கங்கள், வாக்குகளின் எண்ணிக்கை (வாக்கு, பெறு நிதி)
xx…xx = பொது முகவரி (35 எழுத்துகள்)
வாக்களிப்பில் நாம் ஒரே நேரத்தில் பல புலங்களைப் புதுப்பிக்க வேண்டும் என்பதை நினைவில் கொள்ளவும்:
WriteSet([DataEntry(key1, value1), DataEntry(key2, value2)]),
ரைட்செட் ஒன்றுக்குள் ஒரே நேரத்தில் பல பதிவுகளை உருவாக்க அனுமதிக்கிறது அழைப்பிதழ் பரிவர்த்தனைகள்.
பாப் மற்றும் கூப்பர் நிரப்பப்பட்ட பிறகு, 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: []}))
தரவு சேமிப்பகத்தில் நெலியின் முகவரிக்கு தேவையான அனைத்து உள்ளீடுகளையும் பார்க்கிறோம்:
கூப்பரும் நெலி திட்டத்திற்கு வாக்களித்தார்.
செயல்பாட்டுக் குறியீட்டைப் பார்ப்போம் getFunds. 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