Hello vose!
В
Ngatiedzei zvino disassembled zvishoma
Danho 3. Kuedza dApp account
Ndeapi matambudziko anokurumidza kumhanyisa kumanzwi naAlice dApp Akaunti?
Kutanga Kwazvose:
Boob naCooper vanogona kutumira mari netsaona kukero yedApp vachishandisa yakajairwa chinja matransaction uye nekudaro havazokwanise kuwana iwo zvakare.Chipiri:
Isu hatitadzise Alice kubvisa mari pasina mvumo yeBoob uye/kana Cooper. Sezvo, teerera kuti uone, zvese zvekutengesa kubva kuna Alice zvichaitwa.
Ngatigadzirisei 2 nekurambidza Alice chinja kutengeserana. Shandisa script yakagadziriswa:

Tiri kuedza kubvisa mari nedApp Alice uye siginicha yake. Tinowana kukanganisa:
Kuedza kubvisa kuburikidza nekubvisa:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 1000000}]}, payment: []}))
Iyo script inoshanda uye isu takafunga iyo 2nd point!
Danho 4. Gadzira DAO nekuvhota
Nehurombo, mutauro weRIDE hausati wapa kugona kushanda nezviunganidzo (maduramazwi, dictionaries, iterators, reducers, etc.). Nekudaro, kune chero ma operation pane flat collections kiyi-kukosha isu tinokwanisa kugadzira hurongwa hwekushanda netambo, zvichiteerana nemakiyi uye decryption yavo.
Tambo dziri nyore kwazvo kusanganisa, tambo dzinogona kuparadzaniswa neindex.
Ngatiunganidzei uye tipatsanure tambo seyeyedzo kesi uye titarise kuti izvi zvinokanganisa sei mhedzisiro yekutengeserana.
Isu takagadzirisa nyaya yekuti Alice aisakwanisa kusaina Transfer transaction, sezvo mukana uyu wakavharirwa mu @verifier yerudzi urwu rwekutengesa.
Ngatidzidzisei netambo tozogadzirisa izvi.
RIDE Strings
Kutengeserana kunogoneka zvakare, tinoziva kushanda netambo.

Pakazara, isu tine zvese zvaunoda kuti unyore yakaoma logic DAO dApp.
Data Transactions
Data Transactions:
"Kukura kwehukuru hwekiyi mavara zana, uye kiyi inogona kunge iine zvekupokana Unicode kodhi mapoinzi anosanganisira nzvimbo uye mamwe asingadhindike zviratidzo. String values ine muganhu we100 bytes uye huwandu hwepamusoro hwezvingango pinda mu data transaction i32,768. Pakazara, saizi yepamusoro yekutengeserana kwedata inosvika 100kb - yereferensi, hunenge hurefu hwekutamba kwaShakespeare 'Romeo naJuliet. '."
Isu tinogadzira DAO ine anotevera mamiriro:
Kuitira kutanga kuwana mari nekufona getFunds() rutsigiro rwevanongoita 2 vatori vechikamu - DAO investimendi inodiwa. Bvisa zvinogoneka chaizvo sekuwanda kwataridzwa kuvhota DAO varidzi.
Ngatigadzirei marudzi matatu emakiyi uye tiwedzere pfungwa dzekushanda nemabalance mu 3 mabasa matsva vhoti uye getFunds:
xx…xx_ia = vatengesi, mari inowanikwa (vhoti, dhipoziti, kubvisa)
xx…xx_sv = kutanga, nhamba yemavhoti (vhota, getFunds)
xx…xx_sf = kutanga, nhamba yemavhoti (vhota, getFunds)
xx…xx = kero yavose (mavara makumi matatu neshanu)
Ziviso muVhoti taifanira kugadzirisa akati wandei kamwechete:
WriteSet([DataEntry(key1, value1), DataEntry(key2, value2)]),
WriteSet inotibvumira kuita marekodhi akati wandei panguva imwe chete invokeScript kutengeserana.
Aya ndiwo maitiro azvinoita senge mukiyi-kukosha chitoro cheDAO dApp mushure mekunge Bob naCooper vazadzikiswa. ia- deposits:
Basa redu redhipoziti rakachinja zvishoma:
Ikozvino kunouya nguva yakakosha muzviitiko zveDAO - vhota kumapurojekiti ekutsigira mari.
Bob anovhotera chirongwa cheNeli pa500000 wavelets:
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"vote",args:[{type:"integer", value: 500000}, {type:"string", value: "3MrXEKJr9nDLNyVZ1d12Mq4jjeUYwxNjMsH"}]}, payment: []}))
Muchitoro chedata, tinoona zvese zvinodiwa zvekero yeNeli:
Cooper akavhoterawo chirongwa cheNeli.
Ngatitarisei kodhi yebasa getFunds. Neli anofanira kuunganidza mavhoti maviri kuti akwanise kutora mari kubva kuDAO.
Neri achatora hafu yemari yaakapiwa.
broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"getFunds",args:[{type:"integer", value: 500000}]}, payment: []}))
Anobudirira, kureva kuti, DAO inoshanda!
Takaongorora maitiro ekugadzira DAO mumutauro RIDE4DAPPS.
Muzvikamu zvinotevera, isu tichanyatsotarisisa kodhi refactoring uye kesi yekuongorora.
Kodhi yakazara mukati
# 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
}
}
Source: www.habr.com