E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

Hello a pau!

В ʻo ka mua ʻāpana mākou i nānā kikoʻī i ka hana ʻana a me ka hana ʻana me dApp (decentralized application) ma Nalu IDE IDE.

E hoʻāʻo liʻiliʻi i ka mea i wehe ʻia i kēia manawa hiʻohiʻona.

Ka Papa 3. E ho'āʻo ana i ka moʻokāki dApp

E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

He aha nā pilikia e lele koke mai iā ʻoe me Alice? ikal lomi Waihona?
ʻO ka mua
Hiki ke hoʻouna hewa ʻo Boob lāua ʻo Cooper i ke kālā i ka helu dApp me ka hoʻohana maʻamau hoʻoili nā hana a no laila ʻaʻole hiki ke hoʻihoʻi iā lākou.

Piha aku:
ʻAʻole mākou e kaohi iā Alice mai ka unuhi ʻana i ke kālā me ka ʻae ʻole o Boob a me Cooper. No ka mea, e hoʻolohe i ka hōʻoia, e hoʻokō ʻia nā hana āpau mai Alice.

E hoʻoponopono i ka 2nd ma ka pāpā ʻana iā Alice hoʻoili nā kālepa. E hoʻolālā i ka palapala i hoʻoponopono ʻia:
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)
Η
Ke hoʻāʻo nei mākou e hoʻihoʻi i nā kālā mai dApp Alice a me kāna pūlima. Loaʻa iā mākou kahi hewa:
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

E ho'āʻo kākou e haʻalele ma o ka withdraw:

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

Hana ka palapala a ʻike mākou i ka helu 2!

Ka Papa 4. E hana i DAO me ke koho balota

ʻO ka mea pōʻino, ʻaʻole i hāʻawi ʻia ka ʻōlelo RIDE i ka hiki ke hana me nā hōʻiliʻili (nā puke wehewehe ʻōlelo, iterators, reducers, etc.). Eia naʻe, no kēlā me kēia hana me nā hōʻiliʻili pālahalaha ki-waiwai hiki iā mākou ke hoʻolālā i kahi ʻōnaehana no ka hana ʻana me nā kaula, e like me nā kī a me kā lākou decryption.

He maʻalahi loa ka hoʻohui ʻana i nā kaula; hiki ke hoʻokaʻawale ʻia nā kaula e nā kuhikuhi.
E hōʻiliʻili kākou i kahi kaula ma ke ʻano he laʻana hoʻāʻo a nānā i ka hopena o kēia i ka hopena o ke kālepa.
Ua hoʻoholo mākou ʻaʻole hiki iā Alice ke hoʻopaʻa inoa i ke kālepa Transfer, no ka mea, ua pāpā ʻia kēia mana ma @verifier no kēia ʻano kālepa.

E hoʻomaʻamaʻa kāua me nā kaula a laila hoʻoholo i kēia.

HELE LELE

Hiki ke hana hou, ʻike mākou pehea e hana ai me nā kaula.
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

Η
I ka huina, loaʻa iā mākou nā mea a pau e pono ai e kākau i ka loiloi paʻakikī DAO dApp.

Nā Kūʻai ʻIkepili

Nā Kūʻai ʻikepili:
“ʻO ka nui kiʻekiʻe o ke kī he 100 mau huaʻōlelo, a hiki i kahi kī ke loaʻa nā helu code Unicode arbitrary me nā hakahaka a me nā hōʻailona hiki ʻole ke paʻi ʻia. He 32,768 bytes ka nui o nā mea i komo i loko o ke kālepa ʻikepili. ʻO ka holoʻokoʻa, ʻo ka nui o ka nui o kahi kālepa data ma kahi o 100kb - no ka ʻike, kokoke i ka lōʻihi o ka pāʻani ʻo Shakespeare 'Romeo and Juliet. '."

Hana mākou i kahi DAO me kēia mau kūlana:
I mea e loaʻa kālā ai kahi hoʻomaka ma ke kelepona ʻana getFunds() ke kākoʻo o ka liʻiliʻi o 2 mau mea komo - DAO mea hoʻopukapuka - koi ʻia. Haʻalele hiki ke like me ka huina i hoikeia ma koho balota Nā mea nona ka DAO.

E hana mākou i 3 ʻano kī a hoʻohui i ka loiloi no ka hana ʻana me nā kaulike ma 2 mau hana hou koho a loaʻa kālā:
xx…xx_ia = mea hoʻopukapuka kālā, loaʻa koena (koho, waiho, wehe)
xx…xx_sv = hoʻomaka, helu o nā balota (koho, getFunds)
xx…xx_sf = hoʻomaka, helu o nā balota (koho, getFunds)
xx…xx = helu wahi lehulehu (35 huaʻōlelo)

E ʻoluʻolu e hoʻomaopopo i ka Vote pono mākou e hoʻonui i kekahi mau kahua i ka manawa hoʻokahi:

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

Hiki iā WriteSet iā mākou ke hana i kekahi mau moʻolelo i ka manawa hoʻokahi invokeScript nā kālepa.

ʻO kēia ke ʻano o ka waihona waiwai nui o ka DAO dApp, ma hope o ka hoʻopiha ʻana o Bob lāua ʻo Cooper. ia- waiho kālā:
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

Ua loli iki kā mākou hana waihona:
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

Ke hele mai nei ka manawa nui loa i nā hana a DAO - balota no nā papahana e hoʻolilo ʻia.

Koho ʻo Bob no ka papahana hawewele 500000 a Neli:

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

E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

Ma ka hale kūʻai ʻikepili, ʻike mākou i nā mea e pono ai no ka helu wahi o Neli:
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)
Ua koho pū ʻo Cooper i ka papahana Neli.
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

E nānā kākou i ke code hana getFunds. Pono ʻo Neli e hōʻiliʻili i ka liʻiliʻi o 2 mau balota i hiki ke hoʻihoʻi i ke kālā mai ka DAO.
E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

E unuhi ana o Neli i ka hapalua o ke dala i haawiia iaia:

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

E aʻo ana e kākau i nā ʻaelike akamai Waves ma RIDE a me RIDE4DAPPS. Mahele 2 (DAO - Hui Kūʻokoʻa Kūʻokoʻa)

Ua lanakila ʻo ia, ʻo ia hoʻi, hana ʻo DAO!

Ua nānā mākou i ke kaʻina hana o ka hana ʻana i kahi DAO ma ka ʻōlelo RIDE4DAPPS.
Ma nā ʻāpana aʻe e nānā pono mākou i ka code refactoring a me ka hoʻāʻo hihia.

Mana piha o ke code in IDE RIDE o ka nalu:

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

Mahele mua
Code ma GitHub
Nalu IDE IDE
Hoʻolaha o ka papahana hāʻawi

Source: www.habr.com

Pākuʻi i ka manaʻo hoʻopuka