Skip to content

Commit

Permalink
mod - adding certIndex to certificates in txHistory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Eric Bassett committed Aug 3, 2020
1 parent 297a0e4 commit b71a959
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Transactions/types.ts
Expand Up @@ -38,29 +38,35 @@ export type Certificate = StakeRegistration | StakeDeregistration | StakeDelegat

export interface StakeRegistration {
kind: "StakeRegistration";
certIndex: number;
stakeCredential: string;
}
export interface StakeDeregistration{
kind: "StakeDeregistration";
certIndex: number;
stakeCredential: string;
}
export interface StakeDelegation{
kind: "StakeDelegation";
certIndex: number;
stakeCredential: string;
poolKeyHash: string;
}
export interface PoolRegistration{
kind: "PoolRegistration";
certIndex: number;
poolParams: PoolParams;
}
export interface PoolRetirement{
kind: "PoolRetirement";
certIndex: number;
poolKeyHash: string;
epoch: number;

}
export interface MoveInstantaneousRewardsCert{
kind: "MoveInstantaneousRewardsCert";
certIndex: number;
pot: "Reserve" | "Treasury";
rewards: string[];
}
Expand Down
17 changes: 14 additions & 3 deletions src/services/transactionHistory.ts
Expand Up @@ -145,7 +145,11 @@ export const askTransactionHistory = async (
, txHash: obj.f3}));
const outputs = row.outAddrValPairs.map( ( obj:any ): TransOutputFrag => ({ address: obj.f1, amount: obj.f2.toString() }));
const withdrawals : TransOutputFrag[] = row.withdrawals ? row.withdrawals.map( ( obj:any ): TransOutputFrag => ({ address: obj.f1, amount: obj.f2.toString() })) : [];
const certificates = row.certificates ? row.certificates.map(rowToCertificate) : [];
const certificates = row.certificates !== null
? row.certificates
.map(rowToCertificate)
.filter( (i:Certificate|null) => i !== null)
: [];
const blockFrag : BlockFrag = { number: row.blockNumber
, hash: row.blockHash.toString("hex")
, epochNo: row.blockEpochNo
Expand Down Expand Up @@ -175,16 +179,19 @@ export const askTransactionHistory = async (

};

const rowToCertificate = (row:any):Certificate => {
const rowToCertificate = (row:any):Certificate|null => {
switch(row.jsType){
case "StakeRegistration":
return { kind: row.jsType
, certIndex: row.certIndex
, stakeCredential: row.stakeCred };
case "StakeDeregistration":
return { kind: row.jsType
, certIndex: row.certIndex
, stakeCredential: row.stakeCred };
case "StakeDelegation":
return { kind: row.jsType
, certIndex: row.certIndex
, poolKeyHash: row.poolHashKey
, stakeCredential: row.stakeCred };
case "PoolRegistration": {
Expand Down Expand Up @@ -213,20 +220,24 @@ const rowToCertificate = (row:any):Certificate => {
, metadataHash: row.poolParamsMetaDataHash }
};
return { kind: row.jsType
, certIndex: row.certIndex
, poolParams: params};
}
case "PoolRetirement":
return { kind: row.jsType
, certIndex: row.certIndex
, poolKeyHash: row.poolHashKey
, epoch: row.epoch };
case "MoveInstantaneousRewardsCert":
return { kind: row.jsType
, certIndex: row.certIndex
, pot: row.mirPot
, rewards: row.rewards === null
? []
: row.rewards.map( (o:any)=> o.f1) };
default:
throw Error(`Certificate from DB doesn't match any known type: ${row}`);
console.log(`Certificate from DB doesn't match any known type: ${row}`); // the app only logs errors.
return null
}
};

Expand Down

0 comments on commit b71a959

Please sign in to comment.