如何创建白名单作为智能资产?

How to create a whitelist as a smart-asset?

我需要有人帮我创建一个简单的智能资产。我只是希望您不能在任何货币对下进行交易,并且它只能发送到 2 个特定的 Waves 地址。有人可以帮我解决这个问题吗?

您可以使用Data transaction in Waves Console将地址列表添加到发件人帐户(这里我将两个地址添加到白名单),然后将交易广播到网络:

const DataTx = 
data(
{
data: [
{key: "3Mt2yEuqDZVSfN7jqzvtkresLRah329k2ya", value: 12},
{key: "3N17vWKRThx5eKkPLC18UjyUuFr4X3sSKCD", value: 10}], 
fee: 1500000
}
   )
broadcast(DataTx)

对于智能合约,您可以使用pattern matching mechanism只通过检查收件人地址是否在发件人白名单帐户中定义来允许转账交易,否则不允许转账交易:

let whiteListAccount = tx.sender //In this line, we just defined the sender (in our case Bob).
match tx 
{  
case tx : TransferTransaction => let recipient = toBase58String(addressFromRecipient(tx.recipient).bytes)
isDefined(getInteger(whiteListAccount, recipient))
case _ => true 
}

之后您需要编译智能合约并通过 Waves 控制台设置脚本如下:

const Tx = setScript
 (
{
Script: compile(contract()),
senderPublicKey:publicKey(),
Fee:1400000
}
 )

broadcast(Tx)