Skip to content

Commit

Permalink
incoherent checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Nov 13, 2024
1 parent 734c785 commit 77011ce
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 57 deletions.
111 changes: 61 additions & 50 deletions packages/vats/src/orch-purse/mock-orch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,61 @@ import {
* @import {Zone} from '@agoric/base-zone'
*/

const makeMinDenomInfo = (chain, _denom) => {
const brand = {}; // TODO the whole thing
return harden({
brand,
chain,
});
};

/**
* @param {Zone} zone
*/
export const prepareMinOrchestrator = zone => {
const makeMinOrchAccount = zone.exoClass(
'MinOrchAccount',
MinOrchAccountI,
(chain, ledger) => {
const addrValue = `${ledger.size()}`;
return { chain, ledger, addrValue };
(chains, denoms, accounts, chain) => {
const acctAddrValue = `${accounts.size()}`;
return { chains, denoms, accounts, chain, acctAddrValue };
},
{
getAddress() {
const { chain, addrValue: value } = this.state;
const { chain, acctAddrValue } = this.state;
const { chainId } = chain.getChainInfo();
return harden({ chainId, value });
return harden({ chainId, value: acctAddrValue });
},
getBalances() {
const { ledger, addrValue } = this.state;
const { balances } = ledger.get(addrValue);
const { ledger, acctAddrValue } = this.state;
const { balances } = ledger.get(acctAddrValue);
return [...balances.values()];
},
getBalance(denom) {
const { ledger, addrValue } = this.state;
const { balances } = ledger.get(addrValue);
const { ledger, acctAddrValue } = this.state;
const { balances } = ledger.get(acctAddrValue);
return balances.get(denom);
},
transfer(destAddr, denomAmount) {

transfer(_destAddr, _denomAmount) {
// TODO
},
},
);

const makeMinChain = zone.exoClass(
'MinChain',
MinChainI,
chainName => ({
(chains, denoms, chainName) => ({
chains,
denoms,
chainId: chainName,
denoms: zone.mapStore('denoms', {
keyShape: M.string(), // denom
valueShape: MinDenomInfoShape,
}),
ledger: zone.mapStore('accounts', {
keyShape: M.string(), // addrValue
valueShape: {
account: MinOrchAccountShape,
balances: M.remotable('balances'),
},
}),
}),
{
getChainInfo() {
const { chainId } = this.state;
return harden({ chainId });
},
makeAccount() {
const { ledger } = this.state;
const { self } = this;
const account = makeMinOrchAccount(self, ledger);
const { value: addrValue } = account.getAddress();
ledger.init(
addrValue,
const { chains, denoms, chainId } = this.state;
const { accounts } = chains.get(chainId);

const account = makeMinOrchAccount(chains, denoms, accounts, self);
const { value: acctAddrValue } = account.getAddress();
accounts.init(
acctAddrValue,
harden({
account,
balances: zone.mapStore('balances', {
Expand All @@ -96,16 +81,8 @@ export const prepareMinOrchestrator = zone => {
);
return account;
},
getDenomInfo(denom) {
const { denoms } = this.state;
const { self } = this;
return provideLazy(denoms, denom, d => makeMinDenomInfo(self, d));
},
asAmount(denomAmount) {
const { self } = this;
const { denom, value } = denomAmount;
const { brand } = self.getDenomInfo(denom);
return AmountMath.make(brand, value);
makeDenom(_denom) {
// TODO return orchIssuerKit
},
},
);
Expand All @@ -115,14 +92,48 @@ export const prepareMinOrchestrator = zone => {
MinOrchestratorI,
() => ({
chains: zone.mapStore('chains', {
keyShape: M.string(),
valueShape: MinChainShape,
keyShape: M.string(), // chainName === chainId
valueShape: {
chain: MinChainShape,
denoms: M.remotable('denoms'),
accounts: M.remotable('accounts'),
},
}),
denoms: zone.mapStore('denoms', {
keyShape: M.string(), // denom
valueShape: MinDenomInfoShape,
}),
}),
{
getChain(chainName) {
const { chains } = this.state;
return provideLazy(chains, chainName, makeMinChain);
const { chains, denoms } = this.state;
const { chain } = provideLazy(chains, chainName, cName => {
const ch = makeMinChain(chains, denoms, cName);
chains.init(
chainName,
harden({
ch,
accounts: zone.mapStore('accounts', {
keyShape: M.string(), // acctAddrValue
valueShape: {
account: MinOrchAccountShape,
balances: M.remotable('balances'),
},
}),
}),
);
});
return chain;
},
getDenomInfo(denom) {
const { denoms } = this.state;
return denoms.get(denom);
},
asAmount(denomAmount) {
const { self } = this;
const { denom, value } = denomAmount;
const { brand } = self.getDenomInfo(denom);
return AmountMath.make(brand, value);
},
},
);
Expand Down
7 changes: 4 additions & 3 deletions packages/vats/src/orch-purse/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ export const MinChainI = M.interface('MinChain', {
getChainInfo: M.call().returns(M.eref(ChainInfoShape)),
makeAccount: M.call().returns(M.eref(MinOrchAccountShape)),

// In the real API, these are on OrchestratorI
getDenomInfo: M.call(DenomShape).returns(MinDenomInfoShape),
asAmount: M.call(DenomAmountShape).returns(AmountShape),
// TODO returns(OrchIssuerKitShape)
makeDenom: M.call(DenomShape).returns(M.any()),
});

/**
Expand All @@ -73,6 +72,8 @@ export const MinChainI = M.interface('MinChain', {
*/
export const MinOrchestratorI = M.interface('MinOrchestrator', {
getChain: M.call(M.string()).returns(M.eref(MinChainShape)),
getDenomInfo: M.call(DenomShape).returns(MinDenomInfoShape),
asAmount: M.call(DenomAmountShape).returns(AmountShape),
});

// //////////////////////// ERTP-like //////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions packages/vats/src/orch-purse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { Denom, DenomAmount, ChainAddress } from '@agoric/orchestration';
*/
export type MinChainAcctAddr = {
chainId: string;
value: string;
value: string; // acctAddrValue
};

/**
Expand Down Expand Up @@ -50,16 +50,16 @@ export type MinChain = {
getChainInfo(): ERef<MinChainInfo>;
makeAccount(): ERef<MinOrchAccount>;

// In the real API, these are on Orchestrator
getDenomInfo(denom: Denom): MinDenomInfo;
asAmount(denomAmount: DenomAmount): Amount;
makeDenom(denom: Denom): any; // TODO OrchIssuerKit
};

/**
* @see {Orchestrator}
*/
export type MinOrchestrator = {
getChain(chainName: string): ERef<MinChain>;
getDenomInfo(denom: Denom): MinDenomInfo;
asAmount(denomAmount: DenomAmount): Amount;
};

// //////////////////////// ERTP-like //////////////////////////////////////////
Expand Down

0 comments on commit 77011ce

Please sign in to comment.