Created
June 9, 2020 13:45
-
-
Save KardanovIR/5b12ad1ec39bfcb32941d04828f0f878 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# STDLIB_VERSION 4 #-} | |
{-# CONTENT_TYPE EXPRESSION #-} | |
{-# SCRIPT_TYPE ACCOUNT #-} | |
# specifying the ID of a token issued for this team | |
let assetId = base58'...' | |
# the address of an account in which the dApp and team members’ account list will be stored | |
let whiteListAddress = "..." | |
match tx { | |
# Any team member will be able to burn their tokens | |
case b: BurnTransaction => { | |
sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
} | |
# Two signatures are required for updating this script: a team member’s signature | |
# and a signature of the team administrator whose account issues team token | |
case s: SetScriptTransaction => { | |
let assetIssuerPublicKey = assetInfo(assetId).extract().issuerPublicKey | |
sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) && | |
sigVerify(tx.bodyBytes, tx.proofs[1], assetIssuerPublicKey) | |
} | |
# Team tokens can only be transferred between team members, while other tokens can | |
# be transferred if there is an account’s signature | |
case t: TransferTransaction => { | |
# If a token OTHER THAN a team token is transferred, the signature is checked | |
if t.assetId != assetId then sigVerify(t.bodyBytes, t.proofs[0], t.senderPublicKey) else | |
{ | |
# obtaining the recipient’s address as a line | |
let recipientAddress = addressFromRecipient(t.recipient).toString() | |
# converting the team dApp’s address to the type Address | |
let whiteListAddressValue = addressFromStringValue(whiteListAddress) | |
# reading from the team dApp storage by the key | |
# equal to text representation of the current transaction’s recipient address | |
let addressIsAllowed = getBoolean(whiteListAddressValue, recipientAddress) | |
# making sure that the value received from the storage == true | |
# otherwise (if false or Unit) writing false to the variable | |
let addressInWhiteList = match addressIsAllowed { | |
case b: Boolean => b == true | |
case _ => false | |
} | |
# if the recipient’s address is on the team member list | |
# or tokens are transferred to the team’s dApp, then | |
# we check the transaction’s signature (it has to be signed by the account key) | |
if ((addressInWhiteList || recipientAddress == whiteListAddress)) then { | |
if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) | |
then true | |
else | |
throw("Signature is required") | |
}else { | |
throw("You can send this token only to white-listed addresses") | |
} | |
} | |
} | |
# If the dApp function is called | |
# then only the team app is allowed to be called | |
case i: InvokeScriptTransaction => { | |
# obtaining the called app’s address as a line | |
let dappCalledAddress = addressFromRecipient(i.dApp).toString() | |
# if the called app’s address equals the team dApp’s address, then | |
# we request the user’s signature | |
# otherwise we prohibit the call | |
if (dappCalledAddress != whiteListAddress) then throw("You can call only dApp with address " + whiteListAddress + ", but you're trying to call " + dappCalledAddress) else | |
if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) == false) then throw("Transaction should be signed with users key") else | |
true | |
} | |
# We prohibit all other types of transactions, including token exchange, issue etc. | |
case _ => throw("Bad transaction type") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment