ሁሉም ሰው ሰላም!
В
አሁን የተበታተነውን ትንሽ እንፈትሽ
ደረጃ 3. የ dApp መለያን መሞከር
ምን ችግሮች ወዲያውኑ ከአሊስ ጋር ወደ ድምጾች ይሮጣሉ dApp መለያ?
በመጀመሪያ
ቡብ እና ኩፐር መደበኛውን ተጠቅመው በድንገት ገንዘብ ወደ dApp አድራሻ ሊልኩ ይችላሉ። ዝውውር ግብይቶች እና ስለዚህ እነሱን መልሰው ማግኘት አይችሉም።በሁለተኛ ደረጃ
ያለ ቦብ እና/ወይም ኩፐር ፈቃድ አሊስን ገንዘብ እንድታወጣ በምንም መንገድ አንገድበውም። ለማረጋገጥ ትኩረት ይስጡ ፣ ከአሊስ የሚመጡ ሁሉም ግብይቶች ይፈጸማሉ።
አሊስን በማገድ 2 ን እናስተካክል። ዝውውር ግብይቶች. የተስተካከለውን ስክሪፕት አሰማር፡

ሳንቲሞችን ከ dApp አሊስ እና ፊርማ ለማውጣት እየሞከርን ነው። ስህተት አግኝተናል፡-
በመውጣት ለመውጣት በመሞከር ላይ፡-
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 ነው ። በአጠቃላይ ፣ የውሂብ ግብይት ከፍተኛው መጠን 140 ኪ.ባ አካባቢ ነው - ለማጣቀሻ ፣ የሼክስፒር ‹Romeo እና Juliet› ጨዋታ ርዝመት በትክክል ""
ከሚከተሉት ሁኔታዎች ጋር DAO እንፈጥራለን።
ጀማሪ በመደወል የገንዘብ ድጋፍ እንዲያገኝ getFunds() ቢያንስ የ 2 ተሳታፊዎች ድጋፍ - DAO ባለሀብቶች ያስፈልጋሉ። መገንባት ድምር በተጠቀሰው መጠን በትክክል የሚቻል ይሆናል። ድምጽ መስጠት የDAO ባለቤቶች።
እስቲ 3 አይነት ቁልፎችን እንስራ እና ከሂሳብ ጋር ለመስራት አመክንዮ እንጨምር በ2 አዳዲስ ተግባራት ድምጽ እና ፈንዶች፡
xx…xx_ያ = ባለሀብቶች፣ የሚገኝ ቀሪ ሂሳብ (ድምጽ መስጠት፣ ማስያዝ፣ ማውጣት)
xx…xx_sv = ጅምር, የድምጽ ቁጥር (ድምፅ፣ ፈንዶች)
xx…xx_ኤስኤፍ = ጅምር, የድምጽ ቁጥር (ድምፅ፣ ፈንዶች)
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: []}))
በመረጃ ማከማቻው ውስጥ፣ ለኔሊ አድራሻ ሁሉንም አስፈላጊ ግቤቶችን እናያለን፡-
ኩፐር ለኔሊ ፕሮጀክትም ድምጽ ሰጥቷል።
የተግባር ኮድን እንይ 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
}
}
ምንጭ: hab.com