Created
April 6, 2020 13:09
-
-
Save dashameter/69b823de831395ff4e1c95a2951ed6e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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