
Nakong e fetileng Re shebile linyeoe tse 'maloa tsa ho sebelisa liakhaonto tse bohlale khoebong, ho kenyeletsoa lifantisi le mananeo a botšepehi.
Kajeno re tla bua ka hore na li-account tse bohlale le thepa e bohlale li ka ntlafatsang pepeneneng le ho ts'epahala ha lisebelisoa tsa lichelete joalo ka likhetho, bokamoso le likoloto.
Khetho
Khetho ke konteraka ea phapanyetsano e fang moreki tokelo ea ho reka thepa ka theko e itseng kapa pele ho letsatsi le itseng, empa e sa mo tlame ho etsa joalo.
Ts'ebetsong ea khetho e ka ba ka tsela e latelang:
Re sebelisa thepa e bohlale bakeng sa likhetho ka botsona e le sesebelisoa le ak'haonte e bohlale bakeng sa morupeluoa ea sebetsang e le phapanyetsano mme a fana ka likhetho. Motho ea kenang phapanyetsano o tšepisa hore o tla rekisa palo e itseng ea letlotlo le itseng ka sellPrice theko pakeng tsa expirationStart le expirationEnd block heights).
Ka khoutu ea thepa e bohlale, re tla sheba feela hore na e rekisoa feela pakeng tsa libaka tse phahameng tse boletsoeng, 'me e ke ke ea hlahloba ntho leha e le efe e 'ngoe; re tla tlohela boikarabelo bohle ba ho latela melao ho khoutu ea motho ea nkang karolo.
Nomoro ea thepa e bohlale:
let expirationStart = 100000
let expirationEnd = 101440
match tx {
case some : ExchangeTransaction | TransferTransaction =>
height > expirationStart && height <= expirationEnd
case _ => false
}
Re tla nka hore liketso li etsahala ka tsela e latelang: motho ea kenang phapanyetsano o rekisa likhetho tsa ho reka thepa e itseng, 'me barupeluoa ba bang ba ka fetisetsa likhetho tsena kapa ba li rekisa. Ho sebelisa tokelo ea hae ea ho reka, moreki ea nang le bokhoni o tlameha ho fetisetsa palo e lakatsehang ea likhetho ho akhaonto ea morekisi, ke hore, morupeluoa oa phapanyetsano. Ka mor'a moo, o ngola tlhahisoleseding e mabapi le phetisetso e phethiloeng ho akhaonto ea mmuso ea setho sa phapanyetsano, 'me feela ka nako eo ExchangeTransaction e tla khona ho tsoela pele ho ea ka maemo a boletsoeng a theko le thekiso.
Ka khoutu akhaonteng bohlale, re lokela ho etsa bonnete ba hore leha e le efe ExchangeTransaction feta ka eona bakeng sa ketso ea ho qetela ea ho reka le ho rekisa kopana le maemo a boletsweng, 'me morupeluoa reka hantle palo ea diyuniti hore o ile a romela akhaonteng ea morupeluoa phapanyetsano. Motho ea ka khonang ho reka o tlameha ho romela DataTransaction e nepahetseng mabapi le ho fetisoa e le hore motho ea kenang phapanyetsano a ka qoba ho sebelisa chelete habeli. Ho sena DataTransaction, moreki o beha, ho ea ka senotlolo se lekanang le aterese ea hae, boleng bo lekanang le palo ea likhetho tse fetisetsoang tlalehong ea setho sa phapanyetsano, ke hore, palo ea lihlopha tsa thepa eo a ka e rekang.
Smart account khoutu:
#владелец аккаунта дает обязательство продать определенное количество юнитов ассета
#по цене sellPrice между высотами блоков expirationStart и expirationEnd
let expirationStart = 100000
let expirationEnd = 101440
let sellPrice = 10000
let amountAsset = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
let priceAsset = base58'9jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
#ID ассета-опциона
let optionsAsset = base58'7jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
#извлекаем из транзакции адрес отправителя
let this = tx.sender
match tx {
case dataTx : DataTransaction =>
#извлекаем количество юнитов из дата-транзакции по ключу (ID пользователя)
let units = extract(getInteger(dataTx.data, dataTx.data[0].key))
#извлекаем трансфер-транзакцию опционов из пруфа
let e = transactionById(dataTx.proofs[2]) #
match e {
case transferTx : TransferTransaction =>
#убеждаемся, что трансфер был на текущий адрес
(transferTx.recipient == this) &&
#убеждаемся, что отправитель транзакции написал в качестве ключа свой ID
dataTx.data[0].key == toBase58String(transferTx.sender.bytes) &&
sigVerify(dataTx.bodyBytes, dataTx.proofs[0], transferTx.senderPublicKey) &&
#убеждаемся, что указанное количество юнитов соответствует посланному количеству опционов
(units == transferTx.amount) &&
#убеждаемся, что был переведен именно ассет-опцион
(transferTx.assetId == optionsAsset)
case _ => false
} &&
size(dataTx.data) == 1 && !isDefined(getInteger(this, dataTx.data[0].key))
&& height > expirationStart && height <= expirationEnd
case exchangeTx : ExchangeTransaction =>
#убеждаемся, что итоговый обмен происходит по указанным заранее правилам
let correctAssetPair = exchangeTx.sellOrder.assetPair.amountAsset == amountAsset &&
exchangeTx.sellOrder.assetPair.priceAsset == priceAsset
let correctPrice = exchangeTx.sellOrder.price == sellPrice
#извлекаем дата-транзакцию из пруфа
let d = transactionById(exchangeTx.proofs[2])
match d{
case dataTx : DataTransaction =>
let buyOrderSender = dataTx.data[0].key
toBase58String(exchangeTx.buyOrder.sender.bytes) == buyOrderSender &&
exchangeTx.amount == extract(getInteger(dataTx.data, buyOrderSender))
case _ => false
} &&
exchangeTx.sellOrder.sender == this &&
correctAssetPair && correctPrice &&
height > expirationStart && height <= expirationEnd
case _ => false
}
Bokamoso ba li-account tse bohlale
Ho fapana le khetho, bokamoso (konteraka ea bokamoso) ha se tokelo, empa ke boikarabelo ba moreki ho reka thepa ka theko e behiloeng ke konteraka ka nako e itseng nakong e tlang.
Ka kakaretso, ho ngola bokamoso ho tšoana le ho ngola khetho. Mona letlotlo le bohlale le sebetsa e le bokamoso.
U boetse u hloka ho etsa bonnete ba hore moreki le morekisi ba saena taelo ea ho reka. Bokamoso ke tlamo e tlamehang ho phethoa maemong afe kapa afe. Sena se bolela hore haeba morekisi kapa morupeluoa a hana boikarabelo ba bona, motho leha e le ofe ea kenang marang-rang a ka romela transaction, kahoo a phethahatsa bokamoso.
Script ea thepa e bohlale e laola TransferTransactions le ExchangeTransactions tsohle tsa thepa ea nakong e tlang, e ba lumella feela haeba moreki a etsa taelo ea theko ea nakong e tlang ea thepa ea nakong e tlang ho tsoa ho morupeluoa oa phapanyetsano.
Taelo ena e tlameha ho sebetsa 'me e khotsofatse maemo ao bokamoso bo fanoeng tlas'a bona. Ho netefatsa taelo, o ka kenya masimo ohle a eona boemong ba ak'haonte ea moreki hammoho le boemeli ba "byte" ea taelo e saenneng, ebe o etsa netefatso ea kantle.
Hajoale, RIDE ha e na ts'ebetso ea tlhaho ea ho arola li-byte tsa transaction, empa e kenyelletsa lisebelisoa tsohle tse hlokahalang bakeng sa ts'ebetsong ea eona. Ka hona, bahlahisi ba ka leka ho kenya tšebetsong tšobotsi ena ka bobona.
Multi-signature account / Escrow
Ak'haonte e nang le mesaeno e mengata e lumella basebelisi ba bangata ho laola thepa ka kopanelo (mohlala, litšebelisano ka thepa li ka khoneha ha basebelisi ba bararo ho ba bane ba saena). Ho theha liakhaonto tsa mesaeno e mengata ka puo ea RIDE, re ka sebelisa bopaki ba transaction.
Ak'haonte e nang le li-signature tse ngata e ka boela ea sebelisoa e le ak'haonte ea escrow eo ho eona chelete e tšoaroang ho fihlela mekha ea konteraka e phethahatsa boitlamo ba bona.
let alicePubKey = base58'5AzfA9UfpWVYiwFwvdr77k6LWupSTGLb14b24oVdEpMM'
let bobPubKey = base58'2KwU4vzdgPmKyf7q354H9kSyX9NZjNiq4qbnH2wi2VDF'
let cooperPubKey = base58'GbrUeGaBfmyFJjSQb9Z8uTCej5GzjXfRDVGJGrmgt5cD'
#выясняем, кто предоставил корректные подписи
let aliceSigned = if(sigVerify(tx.bodyBytes, tx.proofs[0], alicePubKey)) then 1 else 0
let bobSigned = if(sigVerify(tx.bodyBytes, tx.proofs[1], bobPubKey)) then 1 else 0
let cooperSigned = if(sigVerify(tx.bodyBytes, tx.proofs[2], cooperPubKey)) then 1 else 0
#суммируем все корректные подписи и проверяем их количество
aliceSigned + bobSigned + cooperSigned >= 2
Token curated registry (TCR)
Li-platform tse ngata tsa blockchain li na le bothata ba thepa e chefo. Ka mohlala, aterese leha e le efe e lefileng komisi e ka theha letlotlo ho Waves.
Bothata ba ho sireletsa basebelisi le blockchain ka boeona ho tloha thepa e chefo e ka rarolloa ka token curated registry (TCR) e hlahisoang ke ba nang le matšoao.
Ho vouta bakeng sa tokens e itseng e tla kenyelletsoa lethathamong, mong'a lona o beha tefiso e lekanang le karolo ea hae ea palo eohle ea li-tokens tse fanoeng. Letšoao le kenyelelitsoe rejiseteng haeba bongata ba beng ba eona ba e vouta.
Mohlala oa rona, re lumella mosebelisi ho kenya letšoao lethathamong bakeng sa ho nahaneloa (nakong ea "phephetso") a sebelisa senotlolo sa boemo = asset_name, hafeela boleng ba hona joale ba palo = 0.
Hape, mosebelisi o tlameha ho ba le tekanyo e seng zero ea lets'oao lena sepacheng sa hae. Joale ho tla nako ea ho vouta, eo ka eona mosebelisi a ka voutelang letlotlo le leng le le leng ka sepacheng sa hae, empa hanngoe feela, a fana ka tekanyo ho tloha ho 1 ho isa ho 10. Likhetho tsa basebelisi li emeloa ke linotlolo tsa foromo user_address+assetID.
let asset = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
let addingStartHeight = 1000
let votingStartHeight = 2000
let votingEndHeight = 3000
#извлекаем из транзакции адрес отправителя
let this = extract(tx.sender)
#извлекаем адрес из пруфа транзакции
let address = addressFromPublicKey(tx.proofs[1])
match tx {
case t: DataTransaction =>
if(height > addingStartHeight)
then(
if(height < votingStartHeight)
then(
#adding
#выясняем, есть ли этот ассет у этого адреса
let hasTokens = assetBalance(address, asset) > 0
size(t.data) == 1
#убеждаемся, что этот ассет еще не был добавлен
&& !isDefined(getInteger(this, toBase58String(asset)))
#убеждаемся, что по ключу-ассету добавляется значение равное 0
&& extract(getInteger(t.data, toBase58String(asset))) == 0
&& hasTokens
)
else(
if(height < votingEndHeight)
then
(
#voting
#узнаем текущее количество голосов за данный ассет и задаваемое количество
let currentAmount = extract(getInteger(this, toBase58String(asset)))
let newAmount = extract(getInteger(t.data, toBase58String(asset)))
let betString = toBase58String(address.bytes) + toBase58String(asset)
#убеждаемся, что этот адрес еще не голосовал за этот ассет
let noBetBefore = !isDefined(getInteger(this, betString))
let isBetCorrect = extract(getInteger(t.data, betString)) > 0
&& extract(getInteger(t.data, betString)) <= 10
#убеждаемся, что у голосующего есть необходимые токены
let hasTokens = assetBalance(address, asset) > 0
#проверяем корректность значений транзакции
size(t.data) == 2 && isDefined(getInteger(this, toBase58String(asset)))
&& newAmount == currentAmount + 1
&& noBetBefore && isBetCorrect && hasTokens
)
else false
) && sigVerify(tx.bodyBytes, tx.proofs[0], tx.proofs[1])
)
else false
case _ => false
}
Tefiso ea ho ngolisa
Mohlaleng ona, re tla sheba ts'ebeliso ea li-account tse bohlale ho etsa litefo khafetsa bakeng sa sehlahisoa kapa tšebeletso ka linako tse itseng - "litefiso tsa peeletso".
Haeba mosebelisi a fana ka ak'haonte e bohlale (ka bopaki ba transaction) e nang le ID ea TransferTransaction ka chelete e hlokahalang ea chelete e fetisitsoeng, a ka ngola {key: aterese, bohlokoa:) ho boemo ba akhaonto. 'nete}.
Sena se tla bolela hore mosebelisi o netefatsa peeletso ea bona ho sehlahisoa kapa tšebeletso. Ha ngoliso e felile, mosebelisi ofe kapa ofe oa marang-rang a ka beha boleng haufi le senotlolo se tsamaisanang le mmuso bohata.
let subscriptionPeriod = 44000
let signature = tx.proofs[0]
let pk = tx.proofs[1]
let requiredAmount = 100000
#извлекаем из транзакции адрес отправителя
let this = extract(tx.sender)
match tx {
case d: DataTransaction =>
#извлекаем дату последнего платежа
let lastPaymentHeight = extract(getInteger(this, d.data[0].key + "_lastPayment"))
size(d.data) == 1 && d.data[0].value == "false" && lastPaymentHeight + subscriptionPeriod < height
||
(
let address = d.data[0].key
#извлекаем трансфер-транзакцию по ID, указанному в пруфах
let ttx = transactionById(d.proofs[0])
size(d.data) == 2
&& d.data[0].value == "true"
&& d.data[1].key == address + "_lastPayment"
&& match ttx {
case purchase : TransferTransaction =>
d.data[1].value == transactionHeightById(purchase.id)
&& toBase58String(purchase.sender.bytes) == address
&& purchase.amount == requiredAmount
&& purchase.recipient == this
#убеждаемся, что ассет waves
&& !isDefined(purchase.assetId)
case _ => false
}
)
case _ => false
}
Vouta
Li-account tse bohlale li ka sebelisoa ho kenya tšebetsong likhetho ho blockchain. Mohlala e ka ba ho voutela tlaleho ea moemeli ea hloahloa ka har'a lenaneo la moemeli. Boemo ba akhaonto bo sebelisoa e le sethala sa ho rekota likhetho bakeng sa khetho e itseng.
Mohlala ona, ke ba rekileng li-tokens tse khethehileng tsa "ho vouta" feela ba lumelloang ho vouta. Motho ea nkang karolo o romela DataTransaction esale pele ka para (senotlolo, boleng) = (purchaseTransactionId, buyTransactionId). Ho beha boleng bo bong bakeng sa senotlolo sena ho thibetsoe. U sebelisa aterese ea hau le khetho ea ho vouta, u ka beha DataEntry hang feela. Ho vouta ho ka etsahala feela nakong e boletsoeng.
let asset = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
let address = addressFromPublicKey(tx.proofs[1])
let votingStartHeight = 2000
let votingEndHeight = 3000
#извлекаем из транзакции адрес отправителя
let this = extract(tx.sender)
match tx {
case t: DataTransaction =>
(height > votingStartHeight && height < votingEndHeight) &&
#убеждаемся, что у транзакции правильная подпись
sigVerify(tx.bodyBytes, tx.proofs[0], tx.proofs[1]) &&
#проверяем, что пользователь отдает свой голос напротив своего адреса
if (t.data[0].key == toBase58String(address.bytes))
then (
#извлекаем транзакцию перевод голосовательного токена из пруфов
let purchaseTx = transactionById(t.proofs[7])
match purchaseTx {
case purchase : TransferTransaction =>
let correctSender = purchase.sender == t.sender
let correctAsset = purchase.assetId == asset
let correctPrice = purchase.amount == 1
let correctProof = extract(getBinary(this, toBase58String(purchase.id))) == t.id
correctSender && correctAsset && correctPrice && correctProof
case _ => false
}
)
else
size(t.data) == 1 && !isDefined(getBinary(this, t.data[0].key))
case _ => false
}
Bili ea phapanyetsano
Promissory note ke tlamo e ngotsoeng e hlokang hore motho e mong a lefe e mong chelete e sa fetoheng ha ho hlokahala kapa ka letsatsi le reriloeng esale pele.
Mohlala oa rona, re sebelisa ak'haonte e bohlale, letsatsi la ho felloa ke nako le lumellanang le letsatsi la tefo ea bili.
let expiration = 100000
let amount = 10
let asset = base58'9jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
let Bob = Address(base58'3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8')
let Alice = Address(base58'3PNX6XwMeEXaaP1rf5MCk8weYeF7z2vJZBg')
match tx {
case t: TransferTransaction =>
(t.assetId == asset)&&
(t.amount == amount)&&
(t.sender == Bob)&&
(t.recipient == Alice)&&
(sigVerify(t.bodyBytes, t.proofs[0], t.senderPublicKey))&&
(height >= expiration)
case _ => false
}
Letlapa
Deposit ke ho beha chelete bankeng tlas'a maemo a itseng (nako, phaello).
Mohlala oa rona, mosebetsi oa banka o etsoa ke akhaonto e bohlale. Ka mor'a palo e itseng ea li-blocks, tse tsamaellanang le nako ea depositi, mosebelisi a ka khutlisa chelete ea hae ka phaello. Sengoloa se totobatsa bophahamo ba block (finalHeight), ka mor'a ho fihla moo mosebelisi a ka ntšang chelete ho akhaonto.
heightUnit - palo ea li-blocks ka yuniti e le 'ngoe ea nako (mohlala, khoeli, selemo, joalo-joalo). Pele re hlahloba ho kena ka para (senotlolo, bohlokoa) = (initialTransferTransaction, futureDataTransaction). Joale mosebelisi o tlameha ho fana ka TransferTransaction e nang le tlhaiso-leseling e nepahetseng mabapi le chelete ea depositi le tsoala e fumanoeng nakong ea depositi. Tlhahisoleseding ena e hlahlojwa kgahlanong le TransferTransaction ya mantlha, e leng ka hara bopaki ba hona jwale ba TransferTransaction. depositDivisor ke nomoro e fapaneng ea karolo ea depositi (haeba depositi e amoheloa ho 10%, karolo ea deposit ke 0,1, le depositDevisor = 1/0,1 = 10).
let this = extract(tx.sender)
let depositDivisor = 10
let heightUnit = 1000
let finalHeight = 100000
match tx {
case e : TransferTransaction =>
#извлекаем высоту транзакции по ID транзакции в седьмом пруфе
let depositHeight = extract(transactionHeightById(e.proofs[7]))
#извлекаем транзакцию депозита
let purchaseTx = transactionById(e.proofs[7])
match purchaseTx {
case deposit : TransferTransaction =>
let correctSender = deposit.sender == e.sender
#убеждаемся, что пользователь переводит себе корректную сумму депозита + проценты
let correctAmount = deposit.amount + deposit.amount / depositDivisor * (height - depositHeight) / heightUnit == e.amount
let correctProof = extract(getBinary(this, toBase58String(deposit.id))) == e.id
correctSender && correctProof && correctAmount
case _ => false
}
&& finalHeight <= height
case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
}
Sengoliloeng sa boraro le sa ho qetela letotong lena, re tla sheba ts'ebeliso e ngata ea thepa e bohlale, ho kenyelletsa le ho hoama le ho fokotsa litšebelisano bakeng sa liaterese tse itseng.
Source: www.habr.com
