Skip to content

Commit

Permalink
feat(cosmic-swingset): parse go->node send results as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman authored and mergify[bot] committed Oct 5, 2022
1 parent 525ad88 commit 2839223
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
16 changes: 15 additions & 1 deletion golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gaia

import (
"encoding/json"
"fmt"
"io"
stdlog "log"
Expand Down Expand Up @@ -779,11 +780,24 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) {
VbankPort: app.vbankPort,
LienPort: app.lienPort,
}
_, err := app.SwingSetKeeper.BlockingSend(ctx, action)
out, err := app.SwingSetKeeper.BlockingSend(ctx, action)

// fmt.Fprintf(os.Stderr, "AG_COSMOS_INIT Returned from SwingSet: %s, %v\n", out, err)

if err != nil {
fmt.Fprintln(os.Stderr, "Cannot initialize Controller", err)
os.Exit(1)
}
var res bool
err = json.Unmarshal([]byte(out), &res)
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot unmarshal Controller init response", out, err)
os.Exit(1)
}
if !res {
fmt.Fprintln(os.Stderr, "Controller negative init response")
os.Exit(1)
}
}

// BeginBlocker application updates every begin block
Expand Down
8 changes: 5 additions & 3 deletions golang/cosmos/x/swingset/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package swingset

import (
// "fmt"
// "os"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
Expand Down Expand Up @@ -45,7 +47,7 @@ func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) erro
}
_, err := keeper.BlockingSend(ctx, action)

// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
// fmt.Fprintf(os.Stderr, "BEGIN_BLOCK Returned from SwingSet: %s, %v\n", out, err)
return err
}

Expand All @@ -62,7 +64,7 @@ func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.
}
_, err := keeper.BlockingSend(ctx, action)

// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
// fmt.Fprintf(os.Stderr, "END_BLOCK Returned from SwingSet: %s, %v\n", out, err)
if err != nil {
// NOTE: A failed END_BLOCK means that the SwingSet state is inconsistent.
// Panic here, in the hopes that a replay from scratch will fix the problem.
Expand All @@ -86,7 +88,7 @@ func CommitBlock(keeper Keeper) error {
}
_, err := keeper.BlockingSend(sdk.Context{}, action)

// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
// fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
if err != nil {
// NOTE: A failed COMMIT_BLOCK means that the SwingSet state is inconsistent.
// Panic here, in the hopes that a replay from scratch will fix the problem.
Expand Down
4 changes: 2 additions & 2 deletions golang/cosmos/x/swingset/genesis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package swingset

import (
// "fmt"

// "os"
"fmt"
stdlog "log"

Expand Down Expand Up @@ -52,6 +51,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data *types.GenesisState) []abc

_, err := keeper.BlockingSend(ctx, action)

// fmt.Fprintf(os.Stderr, "BOOTSTRAP_BLOCK Returned from swingset: %s, %v\n", out, err)
if err != nil {
// NOTE: A failed BOOTSTRAP_BLOCK means that the SwingSet state is inconsistent.
// Panic here, in the hopes that a replay from scratch will fix the problem.
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default async function main(progname, args, { env, homedir, agcc }) {
p.then(
res => {
// console.error(`Replying in Node to ${str} with`, res);
replier.resolve(`${res}`);
replier.resolve(stringify(res !== undefined ? res : null));
},
rej => {
// console.error(`Rejecting in Node to ${str} with`, rej);
Expand Down

0 comments on commit 2839223

Please sign in to comment.