Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch 'develop' of https://github.com/luniehq/lunie into ana/m… #5835

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions api/lib/block-listeners/polkadot-node-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class PolkadotNodeSubscription extends BaseNodeSubscription {
`\x1b[36mCurrent session index is ${block.sessionIndex}, fetching validators!\x1b[0m`
)
const [validators, era] = await Promise.all([

dataSource.getAllValidators(),
dataSource.getValidators(),
dataSource.getActiveEra()
])
Expand Down
47 changes: 47 additions & 0 deletions api/lib/reducers/polkadotV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
} = require('../../common/numbers.js')
const { getProposalSummary } = require('./common')
const { lunieMessageTypes } = require('../../lib/message-types')

const {
getMessageTitle,
getPushLink,
Expand Down Expand Up @@ -244,6 +245,11 @@ function undelegationReducer(undelegation, address, network) {
}
}

function transactionsReducerV2(network, extrinsics, blockHeight, reducers) {
// Filter Polkadot tx to Lunie supported types
return extrinsics.reduce((collection, extrinsic) => {
return collection.concat(
transactionReducerV2(network, extrinsic, blockHeight, reducers)
async function transactionsReducerV2(
network,
extrinsics,
Expand Down Expand Up @@ -326,6 +332,46 @@ async function parsePolkadotTransaction(
involvedAddresses: extractInvolvedAddresses(
lunieTransactionType,
signer,
message
)
}
}

function transactionReducerV2(network, extrinsic, blockHeight, reducers) {
const hash = extrinsic.hash
const signer = extrinsic.signature === null ? '' : extrinsic.signature.signer
const isBatch =
extrinsic.method.pallet === `utility` && extrinsic.method.method === `batch`
const messages = aggregateLunieStaking(
isBatch ? extrinsic.args.calls : [extrinsic]
)

// if tx is a batch, we need to check if all of the batched txs went through
let success
if (isBatch) {
success = !!extrinsic.events.find(
(event) =>
event.method.pallet === `utility` &&
event.method.method === `BatchCompleted`
)
} else {
success = !!extrinsic.events.find(
(event) =>
event.method.pallet === `system` &&
event.method.method === `ExtrinsicSuccess`
)
}

return messages.map((message, messageIndex) =>
parsePolkadotTransaction(
hash,
message,
messageIndex,
signer,
success,
network,
blockHeight,
reducers
message,
events
)
Expand Down Expand Up @@ -519,6 +565,7 @@ function sendDetailsReducer(network, message, signer) {
return {
from: [signer],
to: [message.args.dest],
amount: reducers.coinReducer(network, message.args.value)
amount: coinReducer(network, message.args.value)
}
}
Expand Down
Loading