Skip to content

Commit

Permalink
feat(cosmic-swingset): Handle InstallBundle messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed May 25, 2022
1 parent 194e89b commit b72d068
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
26 changes: 26 additions & 0 deletions golang/cosmos/x/swingset/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,29 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision

return &types.MsgProvisionResponse{}, nil
}

type installBundleAction struct {
*types.MsgInstallBundle
Type string `json:"type"` // INSTALL_BUNDLE
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

action := &installBundleAction{
MsgInstallBundle: msg,
Type: "INSTALL_BUNDLE",
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

err := keeper.PushAction(ctx, action)
// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
if err != nil {
return nil, err
}

return &types.MsgInstallBundleResponse{}, nil
}
1 change: 1 addition & 0 deletions packages/cosmic-swingset/src/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export const PLEASE_PROVISION = 'PLEASE_PROVISION';
export const VBANK_BALANCE_UPDATE = 'VBANK_BALANCE_UPDATE';
export const WALLET_ACTION = 'WALLET_ACTION';
export const WALLET_SPEND_ACTION = 'WALLET_SPEND_ACTION';
export const INSTALL_BUNDLE = 'INSTALL_BUNDLE';
12 changes: 12 additions & 0 deletions packages/cosmic-swingset/src/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function makeBlockManager({
saveChainState,
saveOutsideState,
savedHeight,
validateAndInstallBundle,
verboseBlocks = false,
}) {
let computedHeight = savedHeight;
Expand Down Expand Up @@ -79,6 +80,17 @@ export default function makeBlockManager({
break;
}

case ActionType.INSTALL_BUNDLE: {
p = (async () => {
const bundle = JSON.parse(action.bundle);
harden(bundle);
return validateAndInstallBundle(bundle);
})().catch(error => {
console.error(error);
});
break;
}

case ActionType.CORE_EVAL: {
p = doBridgeInbound(BRIDGE_ID.CORE, action);
break;
Expand Down
3 changes: 3 additions & 0 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ export async function launch({
kvStore.get(getHostKey('chainSends')) || '[]',
);

const { validateAndInstallBundle } = controller;

return {
actionQueue,
deliverInbound,
Expand All @@ -333,5 +335,6 @@ export async function launch({
savedHeight,
savedBlockTime,
savedChainSends,
validateAndInstallBundle,
};
}

0 comments on commit b72d068

Please sign in to comment.