From e3f38b6f6c297f16dbfcbd8b04f9adcce9e5ca41 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Wed, 27 Jun 2018 14:50:59 -0700 Subject: [PATCH] Added some documentation --- docs/core/examples/app2.go | 4 ++++ docs/core/examples/app3.go | 3 +++ docs/core/examples/app4.go | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/docs/core/examples/app2.go b/docs/core/examples/app2.go index ff5ee981f..2254210d9 100644 --- a/docs/core/examples/app2.go +++ b/docs/core/examples/app2.go @@ -131,9 +131,11 @@ func handleMsgIssue(keyMain *sdk.KVStoreKey, keyAcc *sdk.KVStoreKey) sdk.Handler return sdk.NewError(2, 1, "IssueMsg is malformed").Result() } + // Retrieve stores store := ctx.KVStore(keyMain) accStore := ctx.KVStore(keyAcc) + // Handle updating metadata if res := handleMetaData(store, issueMsg.Issuer, issueMsg.Coin); !res.IsOK() { return res } @@ -144,6 +146,7 @@ func handleMsgIssue(keyMain *sdk.KVStoreKey, keyAcc *sdk.KVStoreKey) sdk.Handler } return sdk.Result{ + // Return result with Issue msg tags Tags: issueMsg.Tags(), } } @@ -173,6 +176,7 @@ func handleMetaData(store sdk.KVStore, issuer sdk.Address, coin sdk.Coin) sdk.Re } } + // Msg Issuer is not authorized to issue these coins if !reflect.DeepEqual(metadata.Issuer, issuer) { return sdk.ErrUnauthorized(fmt.Sprintf("Msg Issuer cannot issue tokens: %s", coin.Denom)).Result() } diff --git a/docs/core/examples/app3.go b/docs/core/examples/app3.go index 28d51c77a..b48ab5bea 100644 --- a/docs/core/examples/app3.go +++ b/docs/core/examples/app3.go @@ -90,6 +90,7 @@ func betterHandleMsgIssue(metadataMapper MetaDataMapper, accountKeeper bank.Keep return sdk.NewError(2, 1, "Issue Message Malformed").Result() } + // Handle updating metadata if res := betterHandleMetaData(ctx, metadataMapper, issueMsg.Issuer, issueMsg.Coin); !res.IsOK() { return res } @@ -101,6 +102,7 @@ func betterHandleMsgIssue(metadataMapper MetaDataMapper, accountKeeper bank.Keep } return sdk.Result{ + // Return result with Issue msg tags Tags: issueMsg.Tags(), } } @@ -114,6 +116,7 @@ func betterHandleMetaData(ctx sdk.Context, metadataMapper MetaDataMapper, issuer metadata.Issuer = issuer } + // Msg Issuer is not authorized to issue these coins if !reflect.DeepEqual(metadata.Issuer, issuer) { return sdk.ErrUnauthorized(fmt.Sprintf("Msg Issuer cannot issue tokens: %s", coin.Denom)).Result() } diff --git a/docs/core/examples/app4.go b/docs/core/examples/app4.go index c8905f9a9..078a43d8b 100644 --- a/docs/core/examples/app4.go +++ b/docs/core/examples/app4.go @@ -138,16 +138,19 @@ func evenBetterHandleMsgIssue(metadataMapper MetaDataMapper, accountKeeper bank. return sdk.NewError(2, 1, "Issue Message Malformed").Result() } + // Handle updating metadata if res := evenBetterHandleMetaData(ctx, metadataMapper, issueMsg.Issuer, issueMsg.Coin); !res.IsOK() { return res } + // Add newly issued coins to output address _, _, err := accountKeeper.AddCoins(ctx, issueMsg.Receiver, []sdk.Coin{issueMsg.Coin}) if err != nil { return err.Result() } return sdk.Result{ + // Return result with Issue msg tags Tags: issueMsg.Tags(), } } @@ -156,10 +159,12 @@ func evenBetterHandleMsgIssue(metadataMapper MetaDataMapper, accountKeeper bank. func evenBetterHandleMetaData(ctx sdk.Context, metadataMapper MetaDataMapper, issuer sdk.Address, coin sdk.Coin) sdk.Result { metadata := metadataMapper.GetMetaData(ctx, coin.Denom) + // Coin metadata does not exist in store if reflect.DeepEqual(metadata, CoinMetadata{}) { return sdk.ErrInvalidCoins(fmt.Sprintf("Cannot find metadata for coin: %s", coin.Denom)).Result() } + // Msg Issuer not authorized to issue these coins if !reflect.DeepEqual(metadata.Issuer, issuer) { return sdk.ErrUnauthorized(fmt.Sprintf("Msg Issuer cannot issue tokens: %s", coin.Denom)).Result() }