Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Sawubona wonke umntu!

В yokuqala inxenye sijonge ngokweenkcukacha indlela yokuyila nokusebenza nge-dApp (isicelo esinatyisiweyo) kwi Amaza RIYA IDE.

Makhe siyivavanye ngoku le iqhathiweyo mzekelo.

Inqanaba 3. Ukuvavanya i-akhawunti ye-dApp

Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Zeziphi iingxaki eziphuma kuwe ngokukhawuleza noAlice? I-dApp Iakhawunti?
Okokuqala:
UBoob noCooper banokuthumela imali ngempazamo kwidilesi yedApp besebenzisa rhoqo tshintshelo intengiselwano kwaye ke abayi kukwazi ukufikelela kubo emva.

Okwesibini:
Asimthinteli uAlice nangayiphi na indlela ekutsaleni imali ngaphandle kwemvume kaBoob kunye/okanye neCooper. Kuba, nikela ingqalelo ekuqinisekiseni, zonke iintengiselwano ezivela ku-Alice ziya kwenziwa.

Masilungise eye-2 ngokuvala u-Alice tshintshelo iintengiselwano. Masisebenzise iskripthi esilungisiweyo:
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Sizama ukurhoxisa iingqekembe kwi-dApp Alice kunye nokutyikitya kwakhe. Sifumana impazamo:
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Masizame ukurhoxa ngokurhoxa:

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

Isikripthi siyasebenza kwaye sifumene inqaku le-2!

Inqanaba 4. Yenza i-DAO ngokuvota

Ngelishwa, ulwimi lwe-RIDE alukaboneleli ngokukwazi ukusebenza kunye neengqokelela (izichazi-magama zesichazi-magama, ii-iterators, izinciphisi, njl.). Nangona kunjalo, kuyo nayiphi na imisebenzi eneengqokelela ezisicaba isitshixo-ixabiso singakwazi ukuyila inkqubo yokusebenza ngeentambo, ngokuhambelana nezitshixo kunye nokuchithwa kwazo.

Iintambo zilula kakhulu ukudibanisa;
Masiqokelele kwaye sicazulule umtya njengomzekelo wovavanyo kwaye sijonge ukuba oku kusichaphazela njani isiphumo sentengiselwano.
Siye sazinza kwinto yokuba u-Alice akakwazanga ukusayina itransekshini yokuGqithisela, kuba obu buchule bebuvaliwe ku-@verifier kolu hlobo lwentengiselwano.

Masizilolonge ngeentambo kwaye emva koko sisombulule oku.

RIYA Iintambo

Ukuthengiselana kunokwenzeka kwakhona, siyazi indlela yokusebenza ngeentambo.
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)


Lilonke, sinayo yonke into efunekayo ukuze sibhale i-logic entsonkothileyo I-DAO dApp.

IiNtengiselwano zeDatha

IiNtengiselwano zeDatha:
"Obona bukhulu beqhosha bunobumba be-100, kwaye isitshixo sinokuqulatha amanqaku ekhowudi ye-Unicode ebandakanya izithuba kunye nezinye iisimboli ezingaprintwayo. Amaxabiso omtya anomda we-32,768 bytes kunye nenani eliphezulu lokungeniswa okunokwenzeka kwintengiselwano yedatha yi-100. Lilonke, ubungakanani obukhulu bedatha yedatha bujikeleze i-140kb - ireferensi, phantse kanye ubude bomdlalo kaShakespeare 'Romeo noJuliet. '.

Senza i-DAO ngezi meko zilandelayo:
Ukuze uqalise ukufumana inkxaso-mali ngokufowuna getFunds() inkxaso ubuncinane 2 abathathi-nxaxheba - abatyali-mali DAO - iyafuneka. Shenxisa iyakwenzeka kanye njengokuba iyonke ibonakalisiwe ukuvota abanini DAO.

Masenze iintlobo ezi-3 zezitshixo kwaye songeze ingqiqo yokusebenza ngeebhalansi kwivoti yemisebenzi emi-2 kunye ne-GetFunds:
xx…xx_iya = abatyali-mali, ibhalansi ekhoyo (vote, idiphozithi, ukurhoxiswa)
xx…xx_sv = ukuqala, inani leevoti (vote, getFunds)
xx…xx_sf = ukuqala, inani leevoti (vote, getFunds)
xx…xx = idilesi kawonke-wonke (amagama angama-35)

Nceda uqaphele ukuba kwiVoti kufuneka sihlaziye iindawo ezininzi ngexesha elinye:

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

I-WritSet ivumela ukuba senze iirekhodi ezininzi ngexesha elinye invokeScript iintengiselwano.

Yile nto ibonakala ngathi kwi-key-value yogcino lwe-DAO dApp, emva kokuba uBob kunye noCooper bazalise ia-idiphozithi:
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Umsebenzi wethu wediphozithi utshintshile kancinci:
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Ngoku kuza elona xesha libalulekileyo kwimisebenzi ye-DAO - ukuvota ukuze iiprojekthi zixhaswe ngemali.

UBob uvotela iprojekthi kaNeli eyi-500000 yamaza amaza:

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

Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Kwivenkile yedatha sibona zonke izinto eziyimfuneko kwidilesi kaNeli:
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)
UCooper naye wavotela iprojekthi yeNeli.
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Makhe sijonge ikhowudi yomsebenzi getFunds. UNeli kufuneka aqokelele ubuncinane iivoti ezi-2 ukuze akwazi ukutsala imali kwi-DAO.
Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

UNeli uza kutsala isiqingatha semali ayiphathisiweyo:

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

Ukufunda indlela yokubhala ii-Waves smart contracts kwi-RIDE kunye ne-RIDE4DAPPS. Icandelo 2 (DAO - Umbutho oZimeleyo oMiselweyo)

Uyaphumelela, oko kukuthi, iDAO iyasebenza!

Sijonge inkqubo yokwenza iDAO ngolwimi I-RIDE4DAPPS.
Kula macandelo alandelayo siza kuqwalasela ngakumbi ikhowudi yokuhlaziya kunye novavanyo lwamatyala.

Inguqulelo epheleleyo yekhowudi kwi Amaza RIYA 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
    }
}

Inxalenye yokuqala
Ikhowudi kwiGitHub
Amaza RIYA IDE
Isibhengezo senkqubo yesibonelelo

umthombo: www.habr.com

Thenga ukusingathwa okuthembekileyo kwiindawo ezinokhuseleko lweDDoS, iiseva zeVPS VDS 🔥 Thenga ukusingathwa kwewebhusayithi okuthembekileyo ngokhuseleko lwe-DDoS, iiseva zeVPS VDS | ProHoster