Skip to content

Commit

Permalink
Round out stateDB get/set pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Mar 23, 2018
1 parent c5cee7f commit 6aed7d0
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/session/length.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { SESSION_LENGTH } = require('./keys');

module.exports = function length (db: WrapDbInterface): ChainDb$State$Session$Length {
return {
get: (): BN =>
db.getBn64(SESSION_LENGTH()),
set: (length: BN | number): void =>
db.setBn64(SESSION_LENGTH(), length)
};
Expand Down
9 changes: 6 additions & 3 deletions packages/client-db-chain/src/state/session/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
import type BN from 'bn.js';

export type ChainDb$State$Session$Length = {
set (length: BN | number): void,
get: () => BN,
set: (length: BN | number) => void
};

export type ChainDb$State$Session$Value = {
set (id: BN | number, publicKey: Uint8Array): void
get: (id: BN | number) => Uint8Array,
set: (id: BN | number, publicKey: Uint8Array) => void
};

export type ChainDb$State$Session$ValueCount = {
set (count: BN | number): void
get: () => BN,
set: (count: BN | number) => void
}

export type ChainDb$State$Session = {
Expand Down
11 changes: 7 additions & 4 deletions packages/client-db-chain/src/state/session/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const bnToU8a = require('@polkadot/util/bn/toU8a');

const { VALUE } = require('./keys');

function key (id: BN | number): Uint8Array {
return VALUE(bnToU8a(id, 32, true));
}

module.exports = function value (db: WrapDbInterface): ChainDb$State$Session$Value {
return {
get: (id: BN | number): Uint8Array =>
db.get(key(id)),
set: (id: BN | number, publicKey: Uint8Array): void =>
db.set(
VALUE(bnToU8a(id, 32, true)),
publicKey
)
db.set(key(id), publicKey)
};
};
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/session/valueCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { VALUE_LENGTH } = require('./keys');

module.exports = function valueCount (db: WrapDbInterface): ChainDb$State$Session$ValueCount {
return {
get: (): BN =>
db.getBn32(VALUE_LENGTH()),
set: (count: BN | number): void =>
db.setBn32(VALUE_LENGTH(), count)
};
Expand Down
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/staking/currentEra.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { CURRENT_ERA } = require('./keys');

module.exports = function currentEra (db: WrapDbInterface): ChainDb$State$Staking$CurrentEra {
return {
get: (): BN =>
db.getBn32(CURRENT_ERA()),
set: (era: BN | number): void =>
db.setBn64(CURRENT_ERA(), era)
};
Expand Down
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/staking/intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function key (id: BN | number): Uint8Array {

module.exports = function intent (db: WrapDbInterface): ChainDb$State$Staking$Intent {
return {
get: (id: BN | number): Uint8Array =>
db.get(key(id)),
set: (id: BN | number, publicKey: Uint8Array): void =>
db.set(key(id), publicKey)
};
Expand Down
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/staking/intentLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { INTENT_WILL_LENGTH } = require('./keys');

module.exports = function setIntentLength (db: WrapDbInterface): ChainDb$State$Staking$IntentLength {
return {
get: (): BN =>
db.getBn32(INTENT_WILL_LENGTH()),
set: (length: BN | number): void =>
db.setBn32(INTENT_WILL_LENGTH(), length)
};
Expand Down
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/staking/sessionsPerEra.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { SESSIONS_PER_ERA } = require('./keys');

module.exports = function sessionsPerEra (db: WrapDbInterface): ChainDb$State$Staking$SessionsPerEra {
return {
get: (): BN =>
db.getBn64(SESSIONS_PER_ERA()),
set: (count: BN | number): void =>
db.setBn64(SESSIONS_PER_ERA(), count)
};
Expand Down
13 changes: 9 additions & 4 deletions packages/client-db-chain/src/state/staking/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ export type ChainDb$State$Staking$Balance = {
}

export type ChainDb$State$Staking$CurrentEra = {
set (era: BN | number): void,
get: () => BN,
set: (era: BN | number) => void
}

export type ChainDb$State$Staking$Intent = {
set (id: BN | number, publicKey: Uint8Array): void,
get: (id: BN | number) => Uint8Array,
set: (id: BN | number, publicKey: Uint8Array) => void,
}

export type ChainDb$State$Staking$IntentLength = {
set (length: BN | number): void,
get: () => BN,
set: (length: BN | number) => void
}

export type ChainDb$State$Staking$SessionsPerEra = {
set (count: BN | number): void
get: () => BN,
set: (count: BN | number) => void
}

export type ChainDb$State$Staking$ValidatorCount = {
get: () => BN,
set: (count: BN | number) => void
}

Expand Down
2 changes: 2 additions & 0 deletions packages/client-db-chain/src/state/staking/validatorCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { VALIDATOR_COUNT } = require('./keys');

module.exports = function validatorCount (db: WrapDbInterface): ChainDb$State$Staking$ValidatorCount {
return {
get: (): BN =>
db.getBn64(VALIDATOR_COUNT()),
set: (count: BN | number): void =>
db.setBn64(VALIDATOR_COUNT(), count)
};
Expand Down
4 changes: 3 additions & 1 deletion packages/client-db-chain/src/state/system/nonce.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const { NONCE_OF } = require('./keys');
module.exports = function nonce (db: WrapDbInterface): ChainDb$State$System$Nonce {
return {
get: (publicKey: Uint8Array): BN =>
db.getBn64(NONCE_OF(publicKey))
db.getBn64(NONCE_OF(publicKey)),
set: (value: number | BN, publicKey: Uint8Array): void =>
db.detBn64(NONCE_OF(publicKey), value)
};
};
3 changes: 2 additions & 1 deletion packages/client-db-chain/src/state/system/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type ChainDb$State$System$Code = {
};

export type ChainDb$State$System$Nonce = {
get: (publicKey: Uint8Array) => BN
get: (publicKey: Uint8Array) => BN,
set: (nonce: number | BN, publicKey: Uint8Array) => void
};

export type ChainDb$State$System = {
Expand Down

0 comments on commit 6aed7d0

Please sign in to comment.