Skip to content

Commit

Permalink
Merge pull request #11 from ebceu4/add_proof_index_bug
Browse files Browse the repository at this point in the history
fixed addProof incorrect proof index
  • Loading branch information
siemarell authored Nov 9, 2018
2 parents bbf7ade + 1970c24 commit caf4b56
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@ export interface SeedsAndIndexes {
}

export function addProof(tx: WithProofs, proof: string, index?: number) {
if (index == undefined) {
tx.proofs = [...(tx.proofs || []), proof]
return tx
tx.proofs = tx.proofs || [];
if (index == null) {
tx.proofs = [...tx.proofs, proof];
return tx;
}

if (tx.proofs != undefined && tx.proofs[index] != undefined)
throw new Error(`Proof at index ${index} is already exists.`)

tx.proofs = tx.proofs || []

if (tx.proofs != null && !!tx.proofs[index])
throw new Error(`Proof at index ${index} is already exists.`);
for (let i = tx.proofs.length; i < index; i++)
tx.proofs.push(null)

tx.proofs.push(proof)

return tx
tx.proofs.push(null);
tx.proofs[index] = (proof);
return tx;
}

export const valOrDef = <T>(val: T, def: T): T => val != undefined ? val : def
Expand Down

0 comments on commit caf4b56

Please sign in to comment.