-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d4629d
commit 7eb2a52
Showing
19 changed files
with
459 additions
and
208 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package bank | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
. "github.com/cosmos/cosmos-sdk/x/bank" | ||
"github.com/cybercongress/cyberd/cosmos/poc/app/coin" | ||
"github.com/cybercongress/cyberd/cosmos/poc/app/storage" | ||
"reflect" | ||
) | ||
|
||
// NewHandler returns a handler for "bank" type messages. | ||
func NewBankHandler(k Keeper, imms *storage.InMemoryStorage) sdk.Handler { | ||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { | ||
switch msg := msg.(type) { | ||
case MsgSend: | ||
return handleMsgSend(ctx, k, msg, imms) | ||
default: | ||
errMsg := "Unrecognized bank Msg type: " + reflect.TypeOf(msg).Name() | ||
return sdk.ErrUnknownRequest(errMsg).Result() | ||
} | ||
} | ||
} | ||
|
||
// NOTE: totalIn == totalOut should already have been checked | ||
func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend, imms *storage.InMemoryStorage) sdk.Result { | ||
|
||
tags, err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs) | ||
if err != nil { | ||
return err.Result() | ||
} | ||
|
||
for _, input := range msg.Inputs { | ||
imms.UpdateStake(input.Address, -input.Coins.AmountOf(coin.CBD).Int64()) | ||
} | ||
|
||
for _, output := range msg.Outputs { | ||
imms.UpdateStake(output.Address, output.Coins.AmountOf(coin.CBD).Int64()) | ||
} | ||
|
||
return sdk.Result{Tags: tags} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package coin | ||
|
||
const ( | ||
CBD = "CBD" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.