Skip to content

Commit

Permalink
broadcast register peer as soon as hte nft user exists
Browse files Browse the repository at this point in the history
  • Loading branch information
avendauz committed Aug 12, 2021
1 parent b66bec0 commit 944aef5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
16 changes: 8 additions & 8 deletions x/curium/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ func DoBroadcast(resp chan *MsgBroadcasterResponse, keyringDir string, cdc *code
returnError(errors.New("nil error returned"))
}
}()

fmt.Println("Getting keyring")
kr, err := getKeyring(keyringDir)

if err != nil {
returnError(err)
return
}

fmt.Println("Getting account address")
addr, err := getAccountAddress(kr, from)

if addr == nil {
Expand All @@ -207,7 +207,7 @@ func DoBroadcast(resp chan *MsgBroadcasterResponse, keyringDir string, cdc *code
returnError(err)
return
}

fmt.Println("Getting account")
accnt := accKeeper.GetAccount(ctx, addr)

if accnt == nil {
Expand All @@ -221,7 +221,7 @@ func DoBroadcast(resp chan *MsgBroadcasterResponse, keyringDir string, cdc *code
returnError(err)
return
}

fmt.Println("Updating account state")
state, err = updateAccountState(accnt, state)

if err != nil {
Expand All @@ -243,7 +243,7 @@ func DoBroadcast(resp chan *MsgBroadcasterResponse, keyringDir string, cdc *code
gasPrice,
).WithKeybase(kr)


fmt.Println("Building and signing msgs")
signedMsgs, err := txBuilder.BuildAndSign(from, clientkeys.DefaultKeyPass, msgs)


Expand All @@ -258,7 +258,7 @@ func DoBroadcast(resp chan *MsgBroadcasterResponse, keyringDir string, cdc *code
}

rpcCtx := rpctypes.Context{}

fmt.Println("broadcasting")
broadcastResult, err := core.BroadcastTxSync(&rpcCtx, signedMsgs)
if err != nil {
returnError(err)
Expand Down Expand Up @@ -292,15 +292,15 @@ func DoBroadcast(resp chan *MsgBroadcasterResponse, keyringDir string, cdc *code
}()
return
}

fmt.Println("polling for transaction")
result, err := pollForTransaction(rpcCtx, broadcastResult.Hash)


if err != nil {
returnError(err)
return
}

fmt.Println("Sending response back")
resp <- &MsgBroadcasterResponse{
Response: &result.TxResult,
Data: &result.TxResult.Data,
Expand Down
20 changes: 8 additions & 12 deletions x/nft/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,15 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val

if err != nil {
am.keeper.Logger(ctx).Error("nft user does not exist in keyring", "nft", err)
} else {
registerPeerOnce.Do(func () {
go func() {
err := am.keeper.BroadcastRegisterBtPeer(ctx)
if err != nil {
am.keeper.Logger(ctx).Error("Broadcast Register Bt Peer failed", "error", err)
}
}()})
}

if ctx.BlockHeight() > 10 {
if err == nil {
registerPeerOnce.Do(func () {
go func() {
err := am.keeper.BroadcastRegisterBtPeer(ctx)
if err != nil {
am.keeper.Logger(ctx).Error("Broadcast Register Bt Peer failed", "error", err)
}
}()})
}

}
return []abci.ValidatorUpdate{}
}

0 comments on commit 944aef5

Please sign in to comment.