Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('consumer account', `${endpoint}/node/explorer/accounts/${consumer.toAddress()}`);
console.log('consumer tx', `${endpoint}/node/explorer/txs/${res}`);
// 3. create asset for issuer
const asset = {
moniker: 'asset_to_be_consumed',
readonly: true,
transferrable: true,
data: {
typeUrl: 'json',
value: {
key: 'value2',
},
},
};
const assetAddress = toAssetAddress(asset);
asset.address = assetAddress;
res = await client.sendCreateAssetTx({
tx: { itx: asset },
wallet: issuer,
});
console.log('view asset state', `${endpoint}/node/explorer/assets/${assetAddress}`);
console.log('view asset tx', `${endpoint}/node/explorer/txs/${res}`);
// Start multisig for asset consume
const tx = {
from: issuer.toAddress(),
pk: Buffer.from(hexToBytes(issuer.publicKey)), // pk of application
itx: {
issuer: issuer.toAddress(),
},
// eslint-disable-next-line
const json = require(itxFile);
const itxStr = json[Object.keys(json).shift()];
const itxB64 = base64.unescape(itxStr);
debug('itxB64', itxB64);
const itxBuffer = Buffer.from(itxB64, 'base64');
debug('itxBuffer', itxBuffer);
const itxHex = bytesToHex(itxBuffer);
debug('itxHex', itxHex.slice(2).toUpperCase());
const DeployProtocolTx = client.getType('DeployProtocolTx');
const itxObj = DeployProtocolTx.deserializeBinary(itxBuffer).toObject();
itxObj.address = toItxAddress(itxObj, 'DeployProtocolTx');
shell.echo('transaction protocol detail', itxObj);
const hash = await client.sendDeployProtocolTx({
tx: {
nonce: 0,
itx: itxObj,
},
wallet: moderator,
});
shell.echo(`${symbols.success} transaction protocol deploy success`);
shell.echo(`${symbols.info} inspect tx with ${chalk.cyan(`forge tx ${hash}`)}`);
} catch (err) {
debug.error(err);
shell.echo(`${symbols.error} transaction protocol deploy failed`);
}
}
readonly,
transferrable,
data: {
type: 'AssetFactory',
value: {
description: factory.description,
limit: factory.limit,
price: await client.fromTokenToUnit(factory.price),
template: factory.template,
allowedSpecArgs: factory.templateVariables,
assetName: factory.assetName,
attributes: Object.assign({ ttl: 0, transferrable: true }, factory.attributes || {}),
},
},
};
const factoryAddress = toAssetAddress(payload);
payload.address = factoryAddress;
const hash = await client.sendCreateAssetTx(
{
tx: {
itx: payload,
},
delegator,
wallet,
},
extra
);
return [hash, factoryAddress];
};
tx: {
itx: {
value: await client.fromTokenToUnit(token),
assets,
receiver,
hashlock: toBuffer(hashlock),
locktime: finalLocktime,
},
},
delegator,
wallet,
},
extra
);
const address = toSwapAddress(`0x${hash}`);
return [hash, address];
};
client.createAsset = async (
{ moniker, parent = '', ttl = 0, data, readonly = false, transferrable = true, delegator = '', wallet },
extra
) => {
const payload = { moniker, parent, ttl, readonly, transferrable, data };
const address = toAssetAddress(payload);
payload.address = address;
const hash = await client.sendCreateAssetTx(
{
tx: { itx: payload },
delegator,
wallet,
},
extra
);
return [hash, address];
};
const assets = assetVariables.map(x => {
const payload = {
readonly: true,
transferrable: factory.attributes.transferrable,
ttl: factory.attributes.ttl,
parent: assetFactory,
data: {
type: factory.assetName,
value: x,
},
};
const address = toAssetAddress(payload);
return { address, data: JSON.stringify(x) };
});
client.delegate = async ({ from, to, privileges }, extra) => {
let ops = Array.isArray(privileges) ? privileges : [privileges];
ops = ops.map(x => {
if (x.typeUrl && Array.isArray(x.rules)) {
return x;
}
return { typeUrl: x.typeUrl, rules: [] };
});
const txTypes = Object.values(typeUrls).filter(x => x.startsWith('fg:t:'));
if (ops.some(x => txTypes.includes(x.typeUrl) === false)) {
throw new Error('Invalid type url provided for delegation');
}
const address = toDelegateAddress(from.toAddress(), to.toAddress());
const hash = await client.sendDelegateTx(
{
tx: {
itx: {
address,
to: to.toAddress(),
ops,
},
},
wallet: from,
},
extra
);
return [hash, address];
};