Closed a1salimbene closed 7 months ago
@a1salimbene, please add:
git rev-parse --short HEAD
output)sugar
class, as it adds an unpredictable factor we can not test yet@6r1d information request below:
> git rev-parse --short HEAD
7acb8a44
> git branch
iroha2-dev
iroha2-lts
* iroha2-stable
Here's the code without using the sugar
class. I'm getting exact same err:
const transfer = async (from, to, asset, quantity) => {
logger.info(`[srv] transfer ${from} to ${to} ${quantity} of ${asset} ...`);
const [senderAccName, senderDomainId] = from.split('@');
const [receiverAccName, receiverDomainId] = to.split('@');
const [assetName, assetDomainId] = asset.split('#');
const {
AccountId,
AssetDefinitionId,
AssetId,
DomainId,
InstructionExpr,
Expression,
Executable,
IdBox,
NumericValue,
TransferExpr,
Value,
VecInstructionExpr,
} = datamodel;
const senderDomain = DomainId({
name: senderDomainId,
});
const receiverDomain = DomainId({
name: receiverDomainId,
});
const assetDomain = DomainId({
name: assetDomainId,
});
const assetDefinitionId = AssetDefinitionId({
name: assetName,
domain_id: assetDomain,
});
const fromAccount = AccountId({
name: senderAccName,
domain_id: senderDomain,
});
const toAccount = AccountId({
name: receiverAccName,
domain_id: receiverDomain,
});
const amountToTransfer = Value('Numeric', NumericValue('U32', quantity));
const evaluatesToAssetId = (assetId) =>
Expression('Raw', Value('Id', IdBox('AssetId', assetId)));
const transferAssetInstruction = TransferExpr({
source_id: evaluatesToAssetId(
AssetId({
definition_id: assetDefinitionId,
account_id: fromAccount,
})
),
destination_id: evaluatesToAssetId(
AssetId({
definition_id: assetDefinitionId,
account_id: toAccount,
})
),
object: Expression('Raw', amountToTransfer),
});
const instr = InstructionExpr('Transfer', transferAssetInstruction);
const exec = Executable('Instructions', VecInstructionExpr([instr]));
const { pre, client } = _clientFactory('matias', 'cognition');
try {
const data = await client.submitExecutable(pre, exec);
logger.info('[srv] transfer completed ...');
return { data };
} catch (error) {
console.log(error);
return { error: error.message };
}
};
I found the problem looking at a rust test, see below:
fn transfer_isi_should_be_valid() {
let _instruction = TransferExpr::new(
IdBox::AssetId("btc##seller@crypto".parse().expect("Valid")),
12_u32,
IdBox::AccountId("buyer@crypto".parse().expect("Valid")),
);
}
The third param is an AccountId
(destination target), but the first param is an AssetId
(which already includes the source AccountId
.
Thus, this works:
const toAccount = sugar.accountId(receiverAccName, receiverDomainId);
const transferIsi = sugar.instruction.transfer(
datamodel.IdBox('AssetId', sugar.assetId(fromAccount, assetDefinitionId)),
amountToTransfer,
datamodel.IdBox('AccountId', toAccount)
);
but this doesn't
const transferAsset = sugar.instruction.transfer(
datamodel.IdBox('AssetId', sugar.assetId(senderAccId, assetDefId)),
amountToTransfer,
datamodel.IdBox('AssetId', sugar.assetId(receiverAccId, assetDefId))
);
Is worth mentioning that the test case from the JS code appears to be wrong then. In all js samples I found, source and destination IDs are AssetId
. For instance, this is from the JS docs:
const transferAssetInstruction = Instruction(
'Transfer',
TransferBox({
source_id: evaluatesToAssetId(
AssetId({
definition_id: assetDefinitionId,
account_id: fromAccount,
}),
),
destination_id: evaluatesToAssetId(
AssetId({
definition_id: assetDefinitionId,
account_id: toAccount,
}),
),
object: EvaluatesToValue({
expression: Expression('Raw', amountToTransfer),
}),
}),
)
However, this follows the logic from the cli that implements "from" → "to" → "asset", instead of "asset" → "to" like Rust:
iroha_client_cli asset transfer --from matias@cognition --to pepe@cognition --asset-id energy#cognition --quantity 5
So it's all a bit confusing but hopefully, it helps. Now I don't think there's a bug or anything like it. I think this is a case of outdated documentation or lack thereof.
Thank you. I'm closing this issue and will raise the topic with our documentation team.
I'm getting the following error (from node logs):
This is my dev setup:
Node
: stable-2.0.0-pre-rc.20iroha2/client
: 7.0.0iroha2/data-model
: 7.0.0This is my code:
Additional information:
The node is created from the following Dockerfile:
And executed like this: