Comments (4)
@a1salimbene, please add:
- the commit on the stable branch (
git rev-parse --short HEAD
output) - example code without the
sugar
class, as it adds an unpredictable factor we can not test yet
from iroha-javascript.
@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 };
}
};
from iroha-javascript.
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.
from iroha-javascript.
Thank you. I'm closing this issue and will raise the topic with our documentation team.
from iroha-javascript.
Related Issues (20)
- Move to HL-provided runners
- Perform Permissions with Typescript SDK HOT 2
- Move WASM singleton from `@iroha2/client` to `@iroha2/crypto-core`
- Expose "append signature" utility
- Remove `accountId` from the `Signer`
- Include hex utilities into SDK
- Add versioning matrix
- Generate data model as Markdown and track in in Git
- npm init
- Move grpc from devDependencies to dependencies HOT 12
- Add a check that block height is >= 1 HOT 1
- Unexpected type (Quantity / Fixed) HOT 1
- Store asset information is incomplete when querying with JS Api (works with iroha_client_cli) HOT 6
- error executing FindTransactionsByAccountId query HOT 1
- Use original `iroha_crypto` crate HOT 1
- Release new version
- Restructure crypto code HOT 1
- Github branching model HOT 1
- Error while registering a new peer HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iroha-javascript.