Skip to content

Commit 8c7acf2

Browse files
authored
Merge pull request #489 from EYBlockchain/lyd/txHash
This PR adds the transaction hash into the commitment DB. This allows us to detect which commitments originated from the same transaction.
2 parents 592cc48 + fe6463d commit 8c7acf2

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/boilerplate/common/backup-encrypted-data-listener.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ export default class BackupEncryptedDataEventListener {
399399
await storeCommitment({
400400
hash: newCommitment,
401401
name,
402+
transactionHash: eventData.transactionHash || null,
402403
mappingKey: mappingKey?.integer,
403404
type: commitmentType,
404405
typeNames: structTypeNames,

src/boilerplate/common/commitment-storage.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function formatCommitment(commitment) {
8383
_id: commitment.hash.hex(32),
8484
name: commitment.name,
8585
source: commitment.source,
86+
transactionHash: commitment.transactionHash ?? null,
8687
type: commitment.type ?? null,
8788
typeNames: Array.isArray(commitment.typeNames)
8889
? commitment.typeNames

src/boilerplate/common/encrypted-data-listener.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ export default class EncryptedDataEventListener {
7878
.flatMap(e => e.returnValues.nullifiers)
7979
return Promise.all(
8080
backupEvents
81-
.map(e => decrypt(e.returnValues.cipherText, this.publicKey, this.secretKey))
82-
.map(decodeCommitmentData)
81+
.map(e => {
82+
const commitment = decodeCommitmentData(
83+
decrypt(e.returnValues.cipherText, this.publicKey, this.secretKey),
84+
);
85+
if (commitment) commitment.transactionHash = e.transactionHash;
86+
return commitment;
87+
})
8388
.filter(c => c)
8489
.map(formatCommitment)
8590
.map(c => {

src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ sendTransaction = {
687687
isConstructor
688688
}): string[] {
689689
let value;
690+
const transactionHash = isConstructor
691+
? `null`
692+
: `encBackupEvent?.[0]?.transactionHash || null`;
690693
const commitmentType = !Array.isArray(valueType) && ['bytes20', 'address'].includes(valueType)
691694
? `\n type: '${valueType}',`
692695
: '';
@@ -708,6 +711,7 @@ sendTransaction = {
708711
\nawait storeCommitment({
709712
hash: ${stateName}_newCommitment,
710713
name: '${mappingName}',
714+
transactionHash: ${transactionHash},
711715
mappingKey: ${mappingKey === `` ? `null` : `${mappingKey}`},
712716
${commitmentType}
713717
${commitmentTypeNames}
@@ -729,6 +733,7 @@ sendTransaction = {
729733
\nawait storeCommitment({
730734
hash: ${stateName}_2_newCommitment,
731735
name: '${mappingName}',
736+
transactionHash: ${transactionHash},
732737
mappingKey: ${mappingKey === `` ? `null` : `${mappingKey}`},
733738
${commitmentType}
734739
${commitmentTypeNames}
@@ -755,6 +760,7 @@ sendTransaction = {
755760
\nawait storeCommitment({
756761
hash: ${stateName}_newCommitment,
757762
name: '${mappingName}',
763+
transactionHash: ${transactionHash},
758764
mappingKey: ${mappingKey === `` ? `null` : `${mappingKey}`},
759765
${commitmentType}
760766
${commitmentTypeNames}

src/codeGenerators/orchestration/files/toOrchestration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ node.stateVariables?.forEach(
307307
hash: newCommitment,
308308
name: '${variable.name}',
309309
source: 'encrypted data',
310+
transactionHash: eventData.transactionHash || null,
310311
mappingKey: stateVarId.integer,
311312
preimage: {
312313
stateVarId,
@@ -358,6 +359,7 @@ node.stateVariables?.forEach(
358359
hash: newCommitment,
359360
name: '${variable.name}',
360361
source: 'encrypted data',
362+
transactionHash: eventData.transactionHash || null,
361363
mappingKey: stateVarId.integer,
362364
preimage: {
363365
stateVarId,
@@ -811,6 +813,7 @@ const prepareBackupVariable = (node: any) => {
811813
await storeCommitment({
812814
hash: newCommitment,
813815
name: name,
816+
transactionHash: log.transactionHash || null,
814817
mappingKey: mappingKey?.integer,
815818
type: commitmentType,
816819
typeNames: structTypeNames,
@@ -1045,6 +1048,7 @@ const prepareBackupDataRetriever = (node: any) => {
10451048
await storeCommitment({
10461049
hash: newCommitment,
10471050
name: name,
1051+
transactionHash: log.transactionHash || null,
10481052
mappingKey: mappingKey?.integer,
10491053
type: commitmentType,
10501054
typeNames: structTypeNames,

0 commit comments

Comments
 (0)