Skip to content

Commit

Permalink
Translation of updated grpc types
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenbf committed Aug 28, 2024
1 parent 26c3517 commit 3174697
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions packages/sdk/src/grpc/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ function transPoolInfo(info: v2.BakerPoolInfo): v1.BakerPoolInfo {
};
}

function transPaydayStatus(status: v2.PoolCurrentPaydayInfo | undefined): v1.CurrentPaydayBakerPoolStatus | null {
if (!status) {
return null;
}
function transPaydayStatus(status: v2.PoolCurrentPaydayInfo): v1.CurrentPaydayBakerPoolStatus {
return {
blocksBaked: status.blocksBaked,
finalizationLive: status.finalizationLive,
Expand All @@ -330,6 +327,14 @@ function transPaydayStatus(status: v2.PoolCurrentPaydayInfo | undefined): v1.Cur
};
}

function transCooldown(cooldown: v2.Cooldown): v1.Cooldown {
return {
amount: CcdAmount.fromProto(unwrap(cooldown.amount)),
timestamp: Timestamp.fromProto(unwrap(cooldown.endTime)),
status: cooldown.status as number,
};
}

export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo {
const aggAmount = acc.encryptedBalance?.aggregatedAmount?.value;
const numAggregated = acc.encryptedBalance?.numAggregated;
Expand All @@ -346,6 +351,8 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo {
total: CcdAmount.fromProto(unwrap(acc.schedule?.total)),
schedule: unwrap(acc.schedule?.schedules).map(trRelease),
};
const cooldowns = acc.cooldowns.map(transCooldown);
const availableBalance = CcdAmount.fromProto(unwrap(acc.availableBalance));
const accInfoCommon: v1.AccountInfoSimple = {
type: v1.AccountInfoType.Simple,
accountAddress: AccountAddress.fromProto(unwrap(acc.address)),
Expand All @@ -357,6 +364,8 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo {
accountEncryptedAmount: encryptedAmount,
accountReleaseSchedule: releaseSchedule,
accountCredentials: mapRecord(acc.creds, trCred),
accountCooldowns: cooldowns,
accountAvailableBalance: availableBalance,
};

if (acc.stake?.stakingInfo.oneofKind === 'delegator') {
Expand Down Expand Up @@ -531,12 +540,14 @@ export function bakerPoolInfo(info: v2.PoolInfoResponse): v1.BakerPoolStatus {
poolType: v1.PoolStatusType.BakerPool,
bakerId: unwrap(info.baker?.value),
bakerAddress: AccountAddress.fromProto(unwrap(info.address)),
bakerEquityCapital: CcdAmount.fromProto(unwrap(info.equityCapital)),
delegatedCapital: CcdAmount.fromProto(unwrap(info.delegatedCapital)),
delegatedCapitalCap: CcdAmount.fromProto(unwrap(info.delegatedCapitalCap)),
poolInfo: transPoolInfo(unwrap(info?.poolInfo)),
bakerEquityCapital: info.equityCapital !== undefined ? CcdAmount.fromProto(info.equityCapital) : undefined,
delegatedCapital: info.delegatedCapital !== undefined ? CcdAmount.fromProto(info.delegatedCapital) : undefined,
delegatedCapitalCap:
info.delegatedCapitalCap !== undefined ? CcdAmount.fromProto(info.delegatedCapitalCap) : undefined,
poolInfo: info.poolInfo !== undefined ? transPoolInfo(info.poolInfo) : undefined,
bakerStakePendingChange: transPoolPendingChange(info.equityPendingChange),
currentPaydayStatus: transPaydayStatus(info.currentPaydayInfo),
currentPaydayStatus:
info.currentPaydayInfo !== undefined ? transPaydayStatus(info.currentPaydayInfo) : undefined,
allPoolTotalCapital: CcdAmount.fromProto(unwrap(info.allPoolTotalCapital)),
};
}
Expand Down Expand Up @@ -830,8 +841,8 @@ function trBakerEvent(bakerEvent: v2.BakerEvent, account: AccountAddress.Type):
account,
};
}
case undefined:
throw Error('Failed translating BakerEvent, encountered undefined');
default:
throw Error('Unrecognized event type. This should be impossible.');
}
}

Expand All @@ -847,7 +858,7 @@ function trDelegTarget(delegationTarget: v2.DelegationTarget | undefined): v1.Ev
delegateType: v1.DelegationTargetType.PassiveDelegation,
};
} else {
throw 'Failed translating DelegationTarget, encountered undefined';
throw Error('Failed translating DelegationTarget, encountered undefined');
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ export interface BakerPoolStatusDetails {
/** Any pending change to the equity capital. This is not used from protocol version 7 onwards, as stake changes are immediate. */
bakerStakePendingChange: BakerPoolPendingChange;
/** Information of the pool in the current reward period. */
currentPaydayStatus?: CurrentPaydayBakerPoolStatus | null;
currentPaydayStatus?: CurrentPaydayBakerPoolStatus;
/** Total capital staked across all pools, including passive delegation. */
allPoolTotalCapital: CcdAmount.Type;
}
Expand Down Expand Up @@ -1918,5 +1918,5 @@ export type Cooldown = {
/** The amount that is in cooldown and set to be released at the end of the cooldown period */
amount: CcdAmount.Type;
/** The status of the cooldown */
cooldownStatus: CooldownStatus;
status: CooldownStatus;
};

0 comments on commit 3174697

Please sign in to comment.