Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async synchronizeIdentities() {
const transactionsMap = await this.account.getTransactions();
const transactions = Object.keys(transactionsMap).map((txid) => {
return transactionsMap[txid];
});
const outputs = transactions.reduce((outputs, transaction) => {
const preparedOutputs = transaction.outputs.map((output, index) => {
let isBurnOutput;
const outPointBuffer = EvoNetDemoSDK.createOutPointBuffer(transaction.hash, index);
const outputHasTwoChunks = output.script.chunks.length === 2;
if (outputHasTwoChunks) {
const isFirstOpcodeOP_RETURN = output.script.chunks[0].opcodenum === Opcode.map.OP_RETURN;
const isSecondOpcodePubKey = output.script.chunks[1].len === 20;
isBurnOutput = isFirstOpcodeOP_RETURN && isSecondOpcodePubKey;
}
return {
outPointBuffer,
isBurnOutput: isBurnOutput
};
});
return outputs.concat(preparedOutputs);
}, []);
const burnOutputs = outputs.filter((output) => output.isBurnOutput);
const identityIds = burnOutputs.map(burnOutput => {
return bs58.encode(
crypto.Hash.sha256sha256(burnOutput.outPointBuffer)
);
});
const identities = await Promise
.all(identityIds.map(id => {
return this.getIdentityFromNetwork(id)
}));
this.identities = identities.filter(identity => !!identity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.