Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Всем привет!

В muamua vaega na matou vaʻavaʻai auiliili pe faʻapefea ona fatuina ma galulue faʻatasi ma le dApp (decentralized application) i totonu Galu IDE IDE.

Se'i o tatou fa'ata'ita'i la'ititi le mea ua fa'amavae nei faataitaiga.

Laasaga 3. Su'e le tala dApp

Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

O a ni fa'afitauli e vave oso atu ia te oe ma Alice? dApp Teugatupe?
Mea muamua lava:
E ono lafo fa'afuase'i e Boob ma Cooper ni tupe i le tuatusi dApp e fa'aoga masani faaliliuina atu fefaʻatauaʻiga ma o le a le mafai ona toe maua i latou.

Lua:
Matou te le taofia Alice i soo se auala mai le talaina o tupe e aunoa ma le faʻatagaga a Boob ma/poʻo Cooper. Talu ai, faʻalogo lelei i le faʻamaonia, o fefaʻatauaiga uma mai ia Alice o le a faʻataunuʻuina.

Sei o tatou toe faaleleia lona lua e ala i le faasa o Alice faaliliuina atu fefa'ataua'iga. Se'i tatou fa'aogaina le fa'atonuga fa'asa'o:
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

O loʻo matou taumafai e aveese tupe mai le dApp Alice ma lana saini. Ua matou maua se mea sese:
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Tatou taumafai e faaui i tua e ala i le faaui i tua:

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

O loʻo galue le faʻamaumauga ma matou iloa ai le mea lona 2!

Laasaga 4. Fausia se DAO ma le palota

Ae paga lea, o le gagana RIDE e leʻi maua ai le tomai e galue ai ma le aoina (lomifefiloi lomifefiloi, iterators, reducers, etc.). Ae ui i lea, mo soʻo se gaioiga faʻatasi ma faʻaputuga faʻapitoa ki-taua e mafai ona tatou mamanuina se faiga mo le galue i manoa, e tusa ai ma ki ma latou decryption.

O manoa e faigofie tele ona tu'ufa'atasia; e mafai ona tu'u'ese'ese manoa e fa'asino igoa.
Se'i o tatou aoina ma fa'avasega se manoa e fai ma fa'ata'ita'iga fa'ata'ita'iga ma siaki pe fa'afefea ona a'afia ai le i'uga o le fefa'atauaiga.
Na matou faʻamautu i le mea moni e le mafai e Alice ona sainia le fefaʻatauaiga o Fefaʻatauaiga, talu ai na poloka lenei gafatia i @verifier mo lenei ituaiga fefaʻatauaiga.

Tatou faataitai i manoa ona foia lea o lenei mea.

Ti'eti'e Nonoa

E toe mafai le fefaʻatauaiga, matou te iloa le auala e galue ai ma manoa.
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)


I le aotelega, o loʻo ia i matou mea uma e manaʻomia e tusi ai faʻamatalaga faigata DAO dApp.

Fa'amatalaga Fa'amatalaga

Fa'amatalaga Fa'amatalaga:
"O le maualuga maualuga mo se ki e 100 mataitusi, ma o se ki e mafai ona aofia ai faʻailoga Unicode code e aofia ai avanoa ma isi faʻailoga e le mafai ona lolomi. Ole tau ole laina e iai le tapulaʻa o le 32,768 bytes ma le numera maualuga o faʻamatalaga e mafai i faʻamatalaga faʻamatalaga o le 100. I le aotelega, o le maualuga maualuga o se fefaʻatauaiga o faʻamatalaga e tusa ma le 140kb - mo faʻamatalaga, toetoe lava o le umi o le tala a Shakespeare 'Romeo ma Juliet. '.”

Matou te fatuina se DAO ma tulaga nei:
Ina ia mafai e se amataga ona maua tupe e ala i le telefoni getFunds() le lagolago a le itiiti ifo i le 2 tagata auai - DAO investors - e manaʻomia. Aveese e mafai lava e pei o le aofa'i o lo'o fa'aalia i luga palota DAO pule.

Se'i o tatou faia ni ituaiga ki se 3 ma fa'aopoopo le fa'atatau mo le galulue ma paleni i galuega fou e 2 palota ma mauaFunds:
xx…xx_ia = tagata teu tupe, paleni avanoa (palota, teuina, talaina)
xx…xx_sv = amataga, numera o palota (palota, getFunds)
xx…xx_sf = amataga, numera o palota (palota, getFunds)
xx…xx = tuatusi lautele (35 mataitusi)

Faamolemole ia matau o le Vote matou te manaʻomia le faʻafouina o nisi o fanua i le taimi e tasi:

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

TusiSet e mafai ai ona matou faia ni faamaumauga i le taimi e tasi i totonu o le tasi invokeScript fefa'ataua'iga.

O le mea lea e foliga mai i le teuina o le tau o le DAO dApp, ina ua uma ona toe faʻatumu Bob ma Cooper. ia-teuga tupe:
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Ua suia la'ititi la matou galuega teu:
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Ua oʻo mai nei le taimi sili ona taua i gaioiga a DAO - palota mo galuega faatino e faatupeina.

Palota Bob mo le galuega a Neli e 500000 wavelets:

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

Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

I totonu o le faleoloa o faʻamatalaga matou te vaʻai ai i faʻamaumauga uma e manaʻomia mo le tuatusi a Neli:
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)
Na palota foi Cooper mo le galuega a Neli.
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Se'i o tatou va'ai i le code function getFunds. E tatau ona aoina e Neli le itiiti ifo o le 2 palota ina ia mafai ai ona aveese tupe mai le DAO.
Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

O le a aveese e Neli le afa o le tupe na tuuina atu ia te ia:

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

Aoao e tusi Waves atamai konekarate ile RIDE ma RIDE4DAPPS. Vaega 2 (DAO - Fa'alapotopotoga Tuto'atasi Tu'atasi)

Ua manuia o ia, o lona uiga, e galue le DAO!

Na matou vaʻavaʻai i le faagasologa o le fatuina o se DAO i le gagana RIDE4DAPPS.
I vaega o loʻo mulimuli mai o le a tatou vaʻavaʻai totoʻa i le toe faʻaleleia o tulafono ma suʻega mataupu.

Faiga atoa o le code in Galu IDE 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
    }
}

Vaega muamua
Code ile GitHub
Galu IDE IDE
Fa'aaliga o le polokalame fesoasoani

puna: www.habr.com

Faaopoopo i ai se faamatalaga