Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Hello mong le e mong!

В ea pele karolo, re hlahlobile ka botlalo mokhoa oa ho theha le ho sebetsa ka dApp (ts'ebeliso e kenyellelitsoeng) ho Maqhubu PARAMA IDE.

Ha re lekeng hona joale tse harotsoeng hanyane mohlala.

Mothati oa 3. Ho lekola akhaonto ea dApp

Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Ke mathata afe hang-hang a potlakelang ho bua le Alice dApp Ak'haonte?
Pele:
Boob le Cooper ba ka romella chelete ka phoso atereseng ea dApp ba sebelisa e tloaelehileng phetiso 'me ka hona re ke ke ra khona ho li fumana hape.

Bobeli:
Ha re thibele Alice ka tsela efe kapa efe ho ntša chelete ntle le tumello ea Boob le/kapa Cooper. Kaha, ela hloko ho netefatsa, litšebelisano tsohle tse tsoang ho Alice li tla etsoa.

Ha re lokiseng 2 ka ho thibela Alice phetiso ditransekshene. Kenya mongolo o nepahetseng:
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Re leka ho hula lichelete tsa tšepe ka dApp Alice le ho saena ha hae. Re fumana phoso:
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Ho leka ho ikhula ka ho itokolla:

broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 1000000}]}, payment: []}))

Sengoloa se sebetsa mme re fumane ntlha ea 2!

Mothati oa 4. Theha DAO ka ho vouta

Ka bomalimabe, puo ea RIDE ha e e-s'o fane ka bokhoni ba ho sebetsa le likoleke (didikishinari, didikishinari, li-iterator, li-reducers, joalo-joalo). Leha ho le joalo, bakeng sa ts'ebetso efe kapa efe ea likoleke tse bataletseng boleng ba senotlolo re ka qapa mokhoa oa ho sebetsa ka likhoele, ka ho latellana le linotlolo le ho hlakoloa ha tsona.

Likhoele li bonolo haholo ho li kopanya, likhoele li ka aroloa ka li-index.
Ha re bokelleng le ho arola khoele e le teko ea teko 'me re hlahlobe hore na sena se tla ama sephetho sa khoebo joang.
Re ile ra rarolla taba ea hore Alice ha a khone ho saena transaction ea Transfer, kaha monyetla ona o ne o thibetsoe ho @verifier bakeng sa mofuta ona oa thekiso.

Ha re ikoetlise ka likhoele ebe re rarolla sena.

PHAAMA Likhoele

The transaction e ka khoneha hape, re tseba ho sebetsa ka likhoele.
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)


Ka kakaretso, re na le tsohle tseo u li hlokang ho ngola logic e rarahaneng DAO dApp.

Liphetoho tsa data

Data Transactions:
"Boemo bo phahameng ba senotlolo ke litlhaku tse 100, 'me senotlolo se ka ba le lintlha tsa khoutu tsa Unicode tse kenyelletsang libaka le matšoao a mang a sa hatisoeng. Litekanyetso tsa likhoele li na le moeli oa li-byte tse 32,768 'me palo e kholo ea ho kenyelletsoa ha data transaction ke 100. Ka kakaretso, boholo bo boholo ba transaction ea data bo haufi le 140kb - bakeng sa ho buuoa, hoo e batlang e le bolelele ba papali ea Shakespeare 'Romeo le Juliet. '."

Re theha DAO ka maemo a latelang:
E le hore ho qala ho fumana chelete ka ho letsetsa getFunds() tšehetso ea bonyane barupeluoa ba 2 - batseteli ba DAO baa hlokahala. Tlosa e tla khonahala hantle joalo ka ha kakaretso e boletsoe ho vouta Beng ba DAO.

Ha re etseng mefuta e 3 ea linotlolo 'me re kenye mabaka a ho sebetsa ka li-balance ho likhetho tse 2 tse ncha le getFunds:
xx…xx_e = batseteli, tekanyo e fumanehang (khetho, depositi, withdrawal)
xx…xx_sv = ho qala, palo ea likhetho (khetho, fumana chelete)
xx…xx_sf = ho qala, palo ea likhetho (khetho, fumana chelete)
xx…xx = aterese ea sechaba (litlhaku tse 35)

Tsebiso ho Vote re ne re hloka ho nchafatsa likarolo tse 'maloa hang-hang:

WriteSet([DataEntry(key1, value1), DataEntry(key2, value2)]),

WriteSet e re lumella ho etsa lirekoto tse 'maloa ka nako e le' ngoe invokeScript ditransekshene.

Ke kamoo e shebahalang kateng ka lebenkeleng la bohlokoa la DAO dApp ka mor'a hore Bob le Cooper ba tlatse ia- depositi:
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Mosebetsi oa rona oa depositi o fetohile hanyenyane:
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Joale ho tla nako ea bohlokoahali mesebetsing ea DAO - vouta bakeng sa merero ea lichelete.

Bob o voutela morero oa Neli ka li-wavelets tse 500000:

broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"vote",args:[{type:"integer", value: 500000}, {type:"string", value: "3MrXEKJr9nDLNyVZ1d12Mq4jjeUYwxNjMsH"}]}, payment: []}))

Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Ka lebenkeleng la data, re bona likenyo tsohle tse hlokahalang bakeng sa aterese ea Neli:
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)
Cooper o ile a boela a voutela morero oa Neli.
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Ha re shebeng khoutu ea ts'ebetso getFunds. Neli o tlameha ho bokella bonyane livoutu tse 2 hore a tsebe ho hula lichelete ho tsoa ho DAO.
Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

Neli o tlo ntsha halofo ya tjhelete eo a e beilweng:

broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"getFunds",args:[{type:"integer", value: 500000}]}, payment: []}))

Ho ithuta ho ngola likonteraka tse bohlale tsa Waves ho RIDE le RIDE4DAPPS. Karolo ea 2 (DAO - Decentralized Autonomous Organization)

O a atleha, ke hore, DAO ea sebetsa!

Re hlahlobile mokhoa oa ho theha DAO ka puo RIDE4DAPPS.
Likarolong tse latelang, re tla shebisisa mokhoa oa ho fetola khoutu le tlhahlobo ea linyeoe.

Khoutu e felletseng e kene Waves RIDE IDE:

# 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
    }
}

Karolo ea pele
Khoutu ho github
Maqhubu PARAMA IDE
Phatlalatso ea lenaneo la lithuso

Source: www.habr.com

Eketsa ka tlhaloso