Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Aug 3, 2020
1 parent d93d472 commit b082d68
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 27 deletions.
3 changes: 0 additions & 3 deletions app/api/ada/lib/state-fetch/remoteFetcher.js
Expand Up @@ -160,9 +160,6 @@ export class RemoteFetcher implements IFetcher {
withdrawal.address = Buffer.from(payload).toString('hex');
} catch (_e) { /* expected not to work for base58 addresses */ }
}
// the format of this will probably change, so best not to parse it
// so that changing the backend doesn't break the frontend
resp.certificates = [];
}
for (const input of resp.inputs) {
// backend stores inputs as numbers but outputs as strings
Expand Down
45 changes: 24 additions & 21 deletions app/api/ada/lib/state-fetch/types.js
Expand Up @@ -65,7 +65,7 @@ export type RemoteTxState = 'Successful' | 'Failed' | 'Pending';
export type RemoteTransactionShelley = {|
+ttl?: string,
+fee: string,
+certificates: Array<RemoteCertificate>,
+certificates: $ReadOnlyArray<RemoteCertificate>,
+withdrawals: Array<RemoteWithdrawal>,
+metadata: null | string,
|};
Expand Down Expand Up @@ -190,24 +190,27 @@ export type RemoteMoveInstantaneousRewardsCert = {|
+rewards: {| [stake_credential: string]: string /* coin */ |},
|};
export type RemoteCertificate = {|
+type: typeof ShelleyCertificateTypes.StakeRegistration,
...RemoteStakeRegistrationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.StakeDeregistration,
...RemoteStakeDeregistrationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.StakeDelegation,
...RemoteStakeDelegationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.PoolRegistration,
...RemotePoolRegistrationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.PoolRetirement,
...RemotePoolRetirementCert,
|} | {|
+type: typeof ShelleyCertificateTypes.GenesisKeyDelegation,
...RemoteGenesisKeyDelegationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.MoveInstantaneousRewardsCert,
...RemoteMoveInstantaneousRewardsCert,
cert_index: number,
...({|
+type: typeof ShelleyCertificateTypes.StakeRegistration,
...RemoteStakeRegistrationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.StakeDeregistration,
...RemoteStakeDeregistrationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.StakeDelegation,
...RemoteStakeDelegationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.PoolRegistration,
...RemotePoolRegistrationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.PoolRetirement,
...RemotePoolRetirementCert,
|} | {|
+type: typeof ShelleyCertificateTypes.GenesisKeyDelegation,
...RemoteGenesisKeyDelegationCert,
|} | {|
+type: typeof ShelleyCertificateTypes.MoveInstantaneousRewardsCert,
...RemoteMoveInstantaneousRewardsCert,
|})
|};
9 changes: 8 additions & 1 deletion app/api/ada/lib/storage/bridge/updateTransactions.js
Expand Up @@ -1748,7 +1748,7 @@ async function certificateToDb(
dbTx: lf$Transaction,
request: {|
network: number,
certificates: Array<RemoteCertificate>,
certificates: $ReadOnlyArray<RemoteCertificate>,
hashToIds: HashToIdsFunc,
derivationTables: Map<number, string>,
|},
Expand Down Expand Up @@ -1822,6 +1822,7 @@ async function certificateToDb(
const addressId = await addressToId(addrBytes);
result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.StakeRegistration,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down Expand Up @@ -1849,6 +1850,7 @@ async function certificateToDb(
const addressId = await addressToId(addrBytes);
result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.StakeDeregistration,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down Expand Up @@ -1906,6 +1908,7 @@ async function certificateToDb(

result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.StakeDelegation,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down Expand Up @@ -2006,6 +2009,7 @@ async function certificateToDb(

result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.PoolRegistration,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down Expand Up @@ -2043,6 +2047,7 @@ async function certificateToDb(

result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.PoolRetirement,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down Expand Up @@ -2070,6 +2075,7 @@ async function certificateToDb(

result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.GenesisKeyDelegation,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down Expand Up @@ -2113,6 +2119,7 @@ async function certificateToDb(
const certificate = RustModule.WalletV4.MoveInstantaneousRewardsCert.new(certPot);
result.push((txId: number) => ({
certificate: {
Ordinal: cert.cert_index,
Kind: RustModule.WalletV4.CertificateKind.MoveInstantaneousRewardsCert,
Payload: Buffer.from(certificate.to_bytes()).toString('hex'),
TransactionId: txId,
Expand Down
10 changes: 9 additions & 1 deletion app/api/ada/lib/storage/database/index.js
Expand Up @@ -135,7 +135,7 @@ const populateAndCreate = async (
storeType: $Values<typeof schema.DataStoreType>
): Promise<lf$Database> => {
const schemaName = 'yoroi-schema';
const schemaVersion = 13;
const schemaVersion = 14;
const schemaBuilder = schema.create(schemaName, schemaVersion);

populatePrimitivesDb(schemaBuilder);
Expand Down Expand Up @@ -285,4 +285,12 @@ async function onUpgrade(
null
);
}
if (version >= 3 && version <= 13) {
await rawDb.addTableColumn(
'Certificate',
'Ordinal',
// recall: certificates weren't supported at this time
TransactionType.CardanoByron
);
}
}
3 changes: 2 additions & 1 deletion app/api/ada/lib/storage/database/primitives/api/read.js
Expand Up @@ -969,7 +969,8 @@ export class GetCertificates {
request.addressIds
))
.orderBy(blockTable[Tables.BlockSchema.properties.SlotNum], lf.Order.DESC)
.orderBy(txTable[Tables.TransactionSchema.properties.Ordinal], lf.Order.DESC);
.orderBy(txTable[Tables.TransactionSchema.properties.Ordinal], lf.Order.DESC)
.orderBy(txTable[Tables.CertificateSchema.properties.Ordinal], lf.Order.DESC);

const queryResult: $ReadOnlyArray<{|
CertificateAddress: $ReadOnly<CertificateAddressRow>,
Expand Down
3 changes: 3 additions & 0 deletions app/api/ada/lib/storage/database/primitives/tables.js
Expand Up @@ -354,6 +354,7 @@ export type CertificatePart = {|

export type CertificateInsert = {|
TransactionId: number,
Ordinal: number, // transactions can contain multiple certificates in some blockchains
Kind: CertificateKindType | $Values<CertificateKind>,
Payload: string,
|};
Expand All @@ -369,6 +370,7 @@ export const CertificateSchema: {|
properties: {
CertificateId: 'CertificateId',
TransactionId: 'TransactionId',
Ordinal: 'Ordinal',
Kind: 'Kind',
Payload: 'Payload',
}
Expand Down Expand Up @@ -646,6 +648,7 @@ export const populatePrimitivesDb = (schemaBuilder: lf$schema$Builder) => {
schemaBuilder.createTable(CertificateSchema.name)
.addColumn(CertificateSchema.properties.CertificateId, Type.INTEGER)
.addColumn(CertificateSchema.properties.TransactionId, Type.INTEGER)
.addColumn(CertificateSchema.properties.Ordinal, Type.INTEGER)
.addColumn(CertificateSchema.properties.Kind, Type.INTEGER)
.addColumn(CertificateSchema.properties.Payload, Type.STRING)
.addPrimaryKey(
Expand Down
5 changes: 5 additions & 0 deletions app/api/jormungandr/lib/storage/bridge/updateTransactions.js
Expand Up @@ -1587,6 +1587,7 @@ async function certificateToDb(

return (txId: number) => ({
certificate: {
Ordinal: 0, // only one cert per tx in Jormungandr
Kind: kind,
Payload: request.certificate.payloadHex,
TransactionId: txId,
Expand All @@ -1611,6 +1612,7 @@ async function certificateToDb(
}
return (txId: number) => ({
certificate: {
Ordinal: 0, // only one cert per tx in Jormungandr
Kind: kind,
Payload: request.certificate.payloadHex,
TransactionId: txId,
Expand All @@ -1633,6 +1635,7 @@ async function certificateToDb(

return (txId: number) => ({
certificate: {
Ordinal: 0, // only one cert per tx in Jormungandr
Kind: kind,
Payload: request.certificate.payloadHex,
TransactionId: txId,
Expand All @@ -1652,6 +1655,7 @@ async function certificateToDb(
case RustModule.WalletV3.CertificateKind.PoolRetirement: {
return (txId: number) => ({
certificate: {
Ordinal: 0, // only one cert per tx in Jormungandr
Kind: kind,
Payload: request.certificate.payloadHex,
TransactionId: txId,
Expand All @@ -1663,6 +1667,7 @@ async function certificateToDb(
case RustModule.WalletV3.CertificateKind.PoolUpdate: {
return (txId: number) => ({
certificate: {
Ordinal: 0, // only one cert per tx in Jormungandr
Kind: kind,
Payload: request.certificate.payloadHex,
TransactionId: txId,
Expand Down
Expand Up @@ -266,6 +266,7 @@ const delegateCert1 = {
Relation: 0,
}],
certificate: {
Ordinal: 0,
CertificateId: 10,
TransactionId: 14,
Kind: 0,
Expand Down

0 comments on commit b082d68

Please sign in to comment.