Waves smart assets: manane a matsho le a masoeu, khoebo ea nakoana

Waves smart assets: manane a matsho le a masoeu, khoebo ea nakoana

Lihloohong tse peli tse fetileng re buile ka li-account tse bohlale le hore na li ka sebelisoa joang bakeng sa ho tšoara lifantisi le ho theha mananeo a botšepehihape le thuso etsa bonnete ba ponaletso ea lisebelisoa tsa lichelete.

Joale re tla sheba matlotlo a bohlale le linyeoe tse 'maloa tsa ts'ebeliso ea tsona, ho kenyelletsa le thepa ea serame le ho theha lithibelo mabapi le litšebelisano ho liaterese tse boletsoeng.

Waves Smart Assets e lumella basebelisi ho koahela mengolo ho thepa, ba latela mekhanics e tšoanang le ea Smart Accounts. Ts'ebetso e 'ngoe le e' ngoe e ncha e entsoeng ka thepa e bohlale e tla tiisoa pele ke script, 'me feela ka blockchain.

Ho bohlokoa ho ela hloko liphapang tse latelang lipakeng tsa thepa e bohlale le li-account tse bohlale:

  1. Ka khoutu ea thepa e bohlale, ho ke ke ha khoneha ho hlahloba bopaki (re buile ka bona sengolong sa pele).
  2. Khoutung e bohlale ea ak'haonte, o ka sheba ExchangeTransaction ha feela ak'haonte ea hau e le ak'haonte ea matcher. Ho seng joalo, ke taelo feela e hlahlojoang. Ka khoutu ea thepa e bohlale, u ke ke ua hlahloba taelo ka ho toba; u ka hlahloba ExchangeTransaction, 'me, haeba ho hlokahala, u ntše taelo ho eona.
  3. Letlotlo le bohlale, ho fapana le ak'haonte e bohlale, ha le na mmuso, empa re ntse re na le phihlello ea litlaleho tsa akhaonto ho tsoa ho script.

Matlotlo a bohlale a nolofatsa haholo ho ngoloa ha likonteraka, ho etsa hore ts'ebetsong ea linyeoe tse ngata e be e khutšoanyane le e ntle.

Ho hoama

Ho homisa matlotlo ho fihla bophahamong bo itseng ba boloko targetHeight, o ka beha boleng bona ho script ea thepa e latelang e bohlale:

let targetHeight = 1500000
height >= targetHeight
 
height - функция языка, возращающая текущую высоту.

Matcher Specific Maemo

Ho beha sets'oants'o se ikhethileng joalo ka seo u se batlang, o ka beha aterese ea sona joalo ka moromeli ho mongolo o bohlale oa thepa o shebahalang tjena:

match tx {
    case t : ExchangeTransaction =>
        t.sender == addressFromString("3PJaDyprvekvPXPuAtxrapacuDJopgJRaU3")
    case _ => true
}

"Lethathamo le lesoeu" la baamoheli

Ho lumella li-tokens ho romelloa ho li-account tse itseng feela - ho theha "lenane le lesoeu" la baamoheli - o ka sebelisa letlotlo le bohlale le nang le leano le latelang le hlahlobang ho kenyelletsoa lethathamong:

match tx {
  case t : TransferTransaction =>
    let trustedRecipient1 = addressFromString("3P6ms9EotRX8JwSrebeTXYVnzpsGCrKWLv4")
    let trustedRecipient2 = addressFromString("3PLZcCJyYQnfWfzhKXRA4rteCQC9J1ewf5K")
    let trustedRecipient3 = addressFromString("3PHrS6VNPRtUD8MHkfkmELavL8JnGtSq5sx")
    t.recipient == trustedRecipient1 || t.recipient == trustedRecipient2 || t.recipient == trustedRecipient3
  case _ => false
}

Bakeng sa mabaka a ts'ireletso le ho phethahala ha puo, lenane ha le na ts'ebetsong ea phetisetso. Ka hona e hlalosoa e le sehlopha sa likarolo tsa konkreite.

"Lethathamo le letšo" la baamoheli

Ka mokhoa o ts'oanang, ho thibela ho romela li-tokens ho li-account tse itseng, u ka etsa "lethathamo le letšo". Tabeng ena, ho sebelisoa letlotlo le bohlale le tšoanang hantle, empa aterese e hlahlobiloeng ho netefatsa hore ha e lethathamong la batho ba sa tsebeng letho:

match tx {
  case t : TransferTransaction =>
    let bannedRecipient1 = addressFromString("3P6ms9EotRX8JwSrebeTXYVnzpsGCrKWLv4")
    let bannedRecipient2 = addressFromString("3PLZcCJyYQnfWfzhKXRA4rteCQC9J1ewf5K")
    let bannedRecipient3 = addressFromString("3PHrS6VNPRtUD8MHkfkmELavL8JnGtSq5sx")
    t.recipient != bannedRecipient1 && t.recipient != bannedRecipient2 && t.recipient != bannedRecipient3
  case _ => false
}

Ho romelloa ka tumello ea mofani

U sebelisa thepa e bohlale, u ka boela ua beha khetho ea ho romela thepa e bohlale feela ka tumello ea mofani (leibole la boitlamo/mokoloto). Mofani o fana ka tumello ea hae ka ho beha ID ea transaction boemong ba akhaonto ea hae:

match tx {
  case t : TransferTransaction =>
    let issuer = extract(addressFromString("3P6ms9EotRX8JwSrebeTXYVnzpsGCrKWLv4"))
    #убеждаемся, что в стейте эмитента содержится ID текущей транзакции
    isDefined(getInteger(issuer, toBase58String(t.id)))
  case _ => false
}

Phapanyetsano feela bakeng sa lichelete tsa tšepe tse itseng

Letlotlo le bohlale le lumella tumello ea ho le fapanyetsana feela ka lichelete tse itseng tsa tšepe. Mohlala, ho lumella phapanyetsano bakeng sa Bitcoins feela, o ka sebelisa khoutu e latelang:

let BTCId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
match tx {
  case t : ExchangeTransaction =>
    t.sellOrder.assetPair.priceAsset == BTCId ||
     t.sellOrder.assetPair.amountAsset == BTCId
  case _ => true
}

Khoebo ka theko ho tsoa ho oracle

Ho script ea thepa e bohlale, o ka beha tumello ea ho rekisa feela ka theko e behiloeng sebakeng sa oracle e tšepahalang. Mohlala oa mongolo o joalo ke ona:

let oracle = Address(base58'3PLNmokt22NrSiNvCLvwMUP84LCMJqbXwAD')
let assetId = toBase58String(base58'oWgJN6YGZFtZrV8BWQ1PGktZikgg7jzGmtm16Ktyvjd')
 
match tx {
  #запрещаем передачу ассета
  case t: TransferTransaction | MassTransferTransaction => false
  case e: ExchangeTransaction =>
    #убеждаемся, что торговля происходит по цене, заданной в стейте оракла для этого ассета
    let correctPrice = e.price == extract(getInteger(oracle, assetId))
    #убеждаемся, что торговля происходит в обмен на WAVES
    let correctPriceAsset = !isDefined(e.sellOrder.assetPair.priceAsset) 
correctPrice && correctPriceAsset
  case _ => true
}

Mona re tobane le ntlha e sa bonahaleng ha re hlahloba ID ea thepa eo khoebo e etsoang ka eona. Taba ke hore haeba asset ID e sa hlalosoa, joale re bua ka WAVES. Ka script, re etsa bonnete ba hore khoebo e etsoa ka mokhoa o ts'oanang le WAVES, ka tsela ena.

Keketseho ea theko e tsitsitseng

U ka beha theko e tsitsitseng bakeng sa thepa e bohlale, e tla eketsa mohato ka mohato ka tekanyo e fanoeng. Mohlala ke ona oa lengolo la thepa leo theko ea lona e tla eketseha ka 5% li-blocks tse ling le tse ling tse 1000:

let startPrice = 10
let startHeight = 1000
let interval = 1000
#на сколько процентов цена увеличивается за один шаг
let raise = 5
 
match tx {
  case t: TransferTransaction | MassTransferTransaction => false
  case e: ExchangeTransaction =>
    e.price == startPrice + ((height - startHeight) / interval) * (100 + raise) / 100
    && !isDefined(e.sellOrder.assetPair.priceAsset)
  case _ => true
}


Khoebo ea nakoana

Hape, ka lebaka la sengoloa, khoebo ea thepa e bohlale e ka lekanyetsoa ka linako tse reriloeng esale pele. Mohlala oa mongolo o joalo ke ona:

let startHeight = 10000
let interval = 44000
let limit = 1500
 
match tx {
  case t: TransferTransaction | MassTransferTransaction | ExchangeTransaction =>
    (height - startHeight) % interval < limit
  case _ => true
}

Ka script re etsa bonnete ba hore ho tloha qalong ea khoebo qalaBotelele eseng ho feta moedi linako. Bolelele ba nako bo lekana le palo ea li-blocks tse boletsoeng tšimong nako.

Source: www.habr.com

Eketsa ka tlhaloso