Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Cosmos JS #1809

Merged
merged 32 commits into from Mar 14, 2022
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f155a8c
be more conform between optimistic and final operation
alexalouit Mar 8, 2022
24fa16d
use old code logic
alexalouit Mar 9, 2022
9c4dee1
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
3b0a03c
fix senders/recipients regression
alexalouit Mar 9, 2022
d68156c
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
69d62dd
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
86f5367
fix duplicate data
alexalouit Mar 9, 2022
85dddb6
fix duplicate data (again)
alexalouit Mar 9, 2022
c92c461
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
2480c1a
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
565e8be
append block height
alexalouit Mar 9, 2022
4211fb5
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 10, 2022
489cdd8
fix specific empty amount case in reward transaction
alexalouit Mar 10, 2022
5a6b0c6
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 10, 2022
b93e846
temporary debug operation broadcasted
alexalouit Mar 10, 2022
6379b0a
use toOperationRaw method
alexalouit Mar 11, 2022
f05abf7
return patchedOperation
alexalouit Mar 11, 2022
8bda82c
restore broadcast operation
alexalouit Mar 11, 2022
607f359
Update js-synchronisation.ts
alexalouit Mar 11, 2022
eb7198f
remove block height support
alexalouit Mar 11, 2022
ecf61d5
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 11, 2022
44cd92f
Revert "remove block height support"
alexalouit Mar 11, 2022
7a7f6fa
More strict type
alexalouit Mar 11, 2022
8c2dcab
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 11, 2022
78097b8
reverse order of validators
alexalouit Mar 11, 2022
8a34cc7
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 11, 2022
8f2ceb4
fix validators type in createTransmission
alexalouit Mar 11, 2022
e1cf2f0
add sequence to ops
alexalouit Mar 11, 2022
a7a2972
strict output getAccount type
alexalouit Mar 11, 2022
7b7ffe1
fix operations sequence
alexalouit Mar 11, 2022
e60e65b
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 14, 2022
3560296
fix multiple tx messages
alexalouit Mar 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 96 additions & 88 deletions src/families/cosmos/js-synchronisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,96 +38,104 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => {
),
};

tx.logs[0].events.forEach((message) => {
// parse attributes as key:value
const attributes: { [id: string]: any } = {};
message.attributes.forEach((item) => (attributes[item.key] = item.value));

// https://docs.cosmos.network/v0.42/modules/staking/07_events.html
switch (message.type) {
case "transfer":
if (attributes.sender && attributes.recipient && attributes.amount) {
op.senders.push(attributes.sender);
op.recipients.push(attributes.recipient);

if (attributes.amount.indexOf(currency.units[1].code) != -1) {
op.value = op.value.plus(
attributes.amount.replace(currency.units[1].code, "")
);
tx.logs.forEach((log) => {
log.events.forEach((message) => {
// parse attributes as key:value
const attributes: { [id: string]: any } = {};
message.attributes.forEach(
(item) => (attributes[item.key] = item.value)
);

// https://docs.cosmos.network/v0.42/modules/staking/07_events.html
switch (message.type) {
case "transfer":
if (
attributes.sender &&
attributes.recipient &&
attributes.amount
) {
op.senders.push(attributes.sender);
op.recipients.push(attributes.recipient);

if (attributes.amount.indexOf(currency.units[1].code) != -1) {
op.value = op.value.plus(
attributes.amount.replace(currency.units[1].code, "")
);
}

if (!op.type && attributes.sender === address) {
op.type = "OUT";
op.value = op.value.plus(fees);
} else if (!op.type && attributes.recipient === address) {
op.type = "IN";
}
}

if (!op.type && attributes.sender === address) {
op.type = "OUT";
op.value = op.value.plus(fees);
} else if (!op.type && attributes.recipient === address) {
op.type = "IN";
break;

case "withdraw_rewards":
if (
(attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1) ||
// handle specifc case with empty amount value like
// tx DF458FE6A82C310837D7A33735FA5298BCF71B0BFF7A4134641AAE30F6F1050
attributes.amount === ""
) {
op.type = "REWARD";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
}
break;

case "delegate":
if (
attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1
) {
op.type = "DELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
}
break;

case "redelegate":
if (
attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1 &&
attributes.destination_validator &&
attributes.source_validator
) {
op.type = "REDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.destination_validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
op.extra.cosmosSourceValidator = attributes.source_validator;
}
break;

case "unbond":
if (
attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1 &&
attributes.validator
) {
op.type = "UNDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
}
}
break;

case "withdraw_rewards":
if (
(attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1) ||
// handle specifc case with empty amount value like
// tx DF458FE6A82C310837D7A33735FA5298BCF71B0BFF7A4134641AAE30F6F1050
attributes.amount === ""
) {
op.type = "REWARD";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
}
break;

case "delegate":
if (
attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1
) {
op.type = "DELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
}
break;

case "redelegate":
if (
attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1 &&
attributes.destination_validator &&
attributes.source_validator
) {
op.type = "REDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.destination_validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
op.extra.cosmosSourceValidator = attributes.source_validator;
}
break;

case "unbond":
if (
attributes.amount &&
attributes.amount.indexOf(currency.units[1].code) != -1 &&
attributes.validator
) {
op.type = "UNDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
address: attributes.validator,
amount: attributes.amount.replace(currency.units[1].code, ""),
});
}
break;
}
break;
}
});
});

if (!["IN", "OUT"].includes(op.type)) {
Expand Down