-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cosmic-swingset): separate out some of the block manager
- Loading branch information
1 parent
c9b186e
commit d5d2d8a
Showing
3 changed files
with
75 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const BOOTSTRAP_BLOCK = 'BOOTSTRAP_BLOCK'; | ||
export const BEGIN_BLOCK = 'BEGIN_BLOCK'; | ||
export const CALCULATE_FEES_IN_BEANS = 'CALCULATE_FEES_IN_BEANS'; | ||
export const DELIVER_INBOUND = 'DELIVER_INBOUND'; | ||
export const END_BLOCK = 'END_BLOCK'; | ||
export const COMMIT_BLOCK = 'COMMIT_BLOCK'; | ||
export const IBC_EVENT = 'IBC_EVENT'; | ||
export const PLEASE_PROVISION = 'PLEASE_PROVISION'; | ||
export const VBANK_BALANCE_UPDATE = 'VBANK_BALANCE_UPDATE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @ts-check | ||
import { assert, details as X } from '@agoric/assert'; | ||
import { Nat } from '@agoric/nat'; | ||
|
||
export const stringToNat = s => { | ||
assert.typeof(s, 'string', X`${s} must be a string`); | ||
const bint = BigInt(s); | ||
const nat = Nat(bint); | ||
assert.equal( | ||
`${nat}`, | ||
s, | ||
X`${s} must be the canonical representation of ${nat}`, | ||
); | ||
return nat; | ||
}; | ||
|
||
// Map the SwingSet parameters to a deterministic data structure. | ||
export const parseParams = params => { | ||
const { | ||
beans_per_unit: rawBeansPerUnit, | ||
fee_unit_price: rawFeeUnitPrice, | ||
} = params; | ||
assert( | ||
Array.isArray(rawBeansPerUnit), | ||
X`beansPerUnit must be an array, not ${rawBeansPerUnit}`, | ||
); | ||
const beansPerUnit = Object.fromEntries( | ||
rawBeansPerUnit.map(({ key, beans }) => { | ||
assert.typeof(key, 'string', X`Key ${key} must be a string`); | ||
return [key, stringToNat(beans)]; | ||
}), | ||
); | ||
|
||
assert( | ||
Array.isArray(rawFeeUnitPrice), | ||
X`feeUnitPrice ${rawFeeUnitPrice} must be an array`, | ||
); | ||
const feeUnitPrice = rawFeeUnitPrice.map(({ denom, amount }) => { | ||
assert.typeof(denom, 'string', X`denom ${denom} must be a string`); | ||
assert(denom, X`denom ${denom} must be non-empty`); | ||
return { denom, amount: stringToNat(amount) }; | ||
}); | ||
|
||
return { beansPerUnit, feeUnitPrice }; | ||
}; |