11import { assert , q , Fail } from '@endo/errors' ;
2+ import { assertRecord } from '@endo/marshal' ;
3+ import { assertKey , M , mustMatch , isKey } from '@endo/patterns' ;
24import { AmountMath , getAssetKind } from '@agoric/ertp' ;
35import { objectMap } from '@agoric/internal' ;
4- import { assertRecord } from '@endo/marshal' ;
5- import { assertKey , assertPattern , mustMatch , isKey } from '@agoric/store' ;
66import { FullProposalShape } from './typeGuards.js' ;
77
88const { ownKeys } = Reflect ;
@@ -56,25 +56,26 @@ export const cleanKeywords = uncleanKeywordRecord => {
5656 return /** @type {string[] } */ ( keywords ) ;
5757} ;
5858
59- export const coerceAmountPatternKeywordRecord = (
60- allegedAmountKeywordRecord ,
59+ export const coerceAmountBoundKeywordRecord = (
60+ allegedAmountBoundKeywordRecord ,
6161 getAssetKindByBrand ,
6262) => {
63- cleanKeywords ( allegedAmountKeywordRecord ) ;
63+ cleanKeywords ( allegedAmountBoundKeywordRecord ) ;
6464 // FIXME objectMap should constrain the mapping function by the record's type
65- return objectMap ( allegedAmountKeywordRecord , amount => {
65+ return objectMap ( allegedAmountBoundKeywordRecord , amount => {
66+ const { brand, value } = amount ;
6667 // Check that each value can be coerced using the AmountMath
6768 // indicated by brand. `AmountMath.coerce` throws if coercion fails.
6869 if ( isKey ( amount ) ) {
69- const brandAssetKind = getAssetKindByBrand ( amount . brand ) ;
70+ const brandAssetKind = getAssetKindByBrand ( brand ) ;
7071 const assetKind = getAssetKind ( amount ) ;
7172 // TODO: replace this assertion with a check of the assetKind
7273 // property on the brand, when that exists.
7374 assetKind === brandAssetKind ||
7475 Fail `The amount ${ amount } did not have the assetKind of the brand ${ brandAssetKind } ` ;
75- return AmountMath . coerce ( amount . brand , amount ) ;
76+ return AmountMath . coerce ( brand , amount ) ;
7677 } else {
77- assertPattern ( amount ) ;
78+ mustMatch ( value , M . kind ( 'match:containerHas' ) ) ;
7879 return amount ;
7980 }
8081 } ) ;
@@ -90,7 +91,7 @@ export const coerceAmountKeywordRecord = (
9091 allegedAmountKeywordRecord ,
9192 getAssetKindByBrand ,
9293) => {
93- const result = coerceAmountPatternKeywordRecord (
94+ const result = coerceAmountBoundKeywordRecord (
9495 allegedAmountKeywordRecord ,
9596 getAssetKindByBrand ,
9697 ) ;
@@ -153,10 +154,7 @@ export const cleanProposal = (proposal, getAssetKindByBrand) => {
153154 ownKeys ( rest ) . length === 0 ||
154155 Fail `${ proposal } - Must only have want:, give:, exit: properties: ${ rest } ` ;
155156
156- const cleanedWant = coerceAmountPatternKeywordRecord (
157- want ,
158- getAssetKindByBrand ,
159- ) ;
157+ const cleanedWant = coerceAmountBoundKeywordRecord ( want , getAssetKindByBrand ) ;
160158 const cleanedGive = coerceAmountKeywordRecord ( give , getAssetKindByBrand ) ;
161159
162160 const cleanedProposal = harden ( {
0 commit comments