Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ndewo onye ọ bụla!

В nke mbụ akụkụ anyị lere anya n'ụzọ zuru ezu otu esi emepụta ma rụọ ọrụ na dApp (ngwa enweghị isi) na Waves RIDE IDE.

Ka anyị nwalee nke agbasasịla ntakịrị ugbu a ihe atụ.

Nkeji 3. Nnwale akaụntụ dApp

Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Kedu nsogbu gị na Alice na-adakwasị gị ozugbo? Ebuka Akaụntụ?
Nke mbu:
Boob na Cooper nwere ike izipu ego na mberede na adreesị dApp site na iji oge niile nyefe azụmahịa wee si otú a agaghị enwe ike ịnweta ha azụ azụ.

Nke abuo:
Anyị anaghị egbochi Alice n'ụzọ ọ bụla ịdọrọ ego na-enweghị nkwado nke Boob na/ma ọ bụ Cooper. Ebe ọ bụ, ṅaa ntị iji nyochaa, azụmahịa niile sitere na Alice ga-egbu.

Ka anyị dozie nke abụọ site na machibido Alice nyefe azụmahịa. Ka anyị tinye ederede emeziri:
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Anyị na-agbalị ịdọrọ mkpụrụ ego na dApp Alice na mbinye aka ya. Anyị nwetara mperi:
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ka anyị gbalịa ịweghachi site na ndọrọ ndọrọ ọchịchị:

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

Edemede ahụ na-arụ ọrụ ma anyị chọpụta isi ihe nke abụọ!

Nkeji 4. Mepụta DAO na ntuli aka

N'ụzọ dị mwute, asụsụ RIDE enyebeghị ikike ịrụ ọrụ na mkpokọta (akwụkwọ ọkọwa okwu, ndị na-emegharị ihe, ndị na-ebelata, wdg). Otú ọ dị, maka ọrụ ọ bụla nwere nchịkọta dị larịị isi-uru anyị nwere ike chepụta usoro maka iji eriri na-arụ ọrụ, ya mere na igodo na decryption ha.

Ụdọ dị nnọọ mfe concatenate;
Ka anyị chịkọta ma tụgharịa eriri dị ka ihe atụ nnwale wee lelee ka nke a si emetụta nsonaazụ azụmahịa ahụ.
Anyị kwubiri na eziokwu ahụ bụ na Alice enweghị ike ịbanye na azụmahịa Nyefee, ebe ọ bụ na egbochiri ikike a na @verifier maka ụdị azụmahịa a.

Ka anyị jiri eriri na-eme ihe wee dozie nke a.

Ụdọ RIDE

Azụmahịa ahụ ga-ekwe omume ọzọ, anyị maara ka esi arụ ọrụ na eriri.
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)


Na mkpokọta, anyị nwere ihe niile dị mkpa iji dee mgbagha mgbagwoju anya DAO dApp.

Azụmahịa data

Azụmahịa data:
“Nha kacha maka igodo bụ mkpụrụedemede 100, igodo nwere ike ịnwe isi koodu Unicode na-ezighi ezi gụnyere oghere na akara ndị ọzọ anaghị ebi ebi. Ụkpụrụ eriri nwere oke nke 32,768 bytes na ọnụ ọgụgụ kachasị nke ntinye aka na azụmahịa data bụ 100. N'ozuzu, oke nke azụmahịa data dị gburugburu 140kb - maka ntụaka, ihe fọrọ nke nta ka ọ bụrụ ogologo oge nke Shakespeare's play 'Romeo na Juliet '.

Anyị na-emepụta DAO na ọnọdụ ndị a:
Ka onye mbido nweta ego site na ịkpọ nweta ego () nkwado nke opekata mpe 2 sonyere - DAO investors - chọrọ. Wepụ ọ ga-ekwe omume kpọmkwem dị ka ngụkọta egosiri na ya ịtụ vootu Ndị nwe DAO.

Ka anyị mee ụdị igodo 3 wee gbakwunye mgbagha maka ịrụ ọrụ na nguzozi na votu ọrụ ọhụrụ abụọ na nwetaFunds:
xx… xx_a = ndị investors, nguzozi dị (votu, nkwụnye ego, ndọrọ ego)
xx… xx_sv = mmalite, ọnụọgụ votu (votu, getFunds)
xx… xx_sf = mmalite, ọnụọgụ votu (votu, getFunds)
xx…xx = adreesị ọha ( mkpụrụedemede 35)

Biko mara na na votu anyị kwesịrị imelite ọtụtụ ubi ozugbo:

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

WriteSet na-enye anyị ohere ịme ọtụtụ ndekọ n'otu oge n'ime otu invokeScript azụmahịa.

Nke a bụ ihe ọ dị na nchekwa igodo-uru nke DAO dApp, mgbe Bob na Cooper mechachara. ia- nkwụnye ego:
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ọrụ nkwụnye ego anyị agbanweela ntakịrị:
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ugbu a na-abịa oge kachasị mkpa na mmemme DAO - votu maka oru ngo a ga-enweta ego.

Bob tụrụ vootu maka ọrụ ụgbọ mmiri 500000 nke Neli:

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

Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

N'ime ụlọ ahịa data anyị na-ahụ ndenye niile dị mkpa maka adreesị Neli:
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)
Cooper tụkwara vootu maka ọrụ Neli.
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ka anyị leba anya na koodu ọrụ nweta ego. Neli ga-anakọta opekempe nke 2 votes iji nwee ike ịdọrọ ego na DAO.
Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Neli ga-ewepụ ọkara nke ego e nyere ya:

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

Ịmụ ka esi ede nkwekọrịta smart Waves na RIDE na RIDE4DAPPS. Nkebi nke 2 (DAO - Òtù Na-achịkọta Onwe Ya)

Ọ na-eme nke ọma, ya bụ, DAO na-arụ ọrụ!

Anyị lere anya usoro ịmepụta DAO n'asụsụ ahụ RIDE4DAPPS.
N'akụkụ ndị a, anyị ga-elebakwu anya na nhazi koodu na ule ikpe.

Ụdị koodu ahụ zuru oke n'ime 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
    }
}

Akụkụ mbụ
Koodu na GitHub
Waves RIDE IDE
Nkwupụta nke mmemme inye onyinye

isi: www.habr.com

Zụta nnabata ntụkwasị obi maka saịtị nwere nchekwa DDoS, sava VPS VDS 🔥 Zụta ebe nrụọrụ weebụ a pụrụ ịtụkwasị obi na nchekwa DDoS, sava VPS VDS | ProHoster