-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pegzone witness #3
Open
junbeomlee
wants to merge
3
commits into
develop
Choose a base branch
from
pegzone-witness
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,11 @@ | ||
module github.com/DE-labtory/erc20peggy | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/cosmos/cosmos-sdk v0.34.3 | ||
github.com/gogo/protobuf v1.2.1 | ||
github.com/gorilla/mux v1.7.1 | ||
github.com/spf13/cobra v0.0.3 | ||
github.com/tendermint/tendermint v0.31.5 | ||
) |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pegzone |
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,61 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/DE-labtory/erc20peggy/pegzone/x/witness" | ||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/client/utils" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GetLockCmd(cdc *codec.Codec) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "lock [address] [data]", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc) | ||
if err := cliCtx.EnsureAccountExists(); err != nil { | ||
return err | ||
} | ||
|
||
data, err := json.Marshal(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := witness.NewMsgLock(data, args[1], cliCtx.GetFromAddress()) | ||
err = msg.ValidateBasic() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cliCtx.PrintResponse = true | ||
return utils.GenerateOrBroadcastMsgs( | ||
cliCtx, | ||
authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)), | ||
[]sdk.Msg{msg}, | ||
false, | ||
) | ||
}, | ||
} | ||
} |
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,78 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package rest | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/DE-labtory/erc20peggy/pegzone/x/witness" | ||
"github.com/cosmos/cosmos-sdk/client/context" | ||
clientrest "github.com/cosmos/cosmos-sdk/client/rest" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/rest" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
const ( | ||
restName = "pegzone" | ||
) | ||
|
||
// RegisterRoutes - Central function to define routes that get registered by the main application | ||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { | ||
r.HandleFunc(fmt.Sprintf("/%s/lock", restName), lockHandler(cdc, cliCtx)).Methods("POST") | ||
} | ||
|
||
type lockReq struct { | ||
BaseReq rest.BaseReq `json:"base_req"` | ||
Data []byte `json:"data"` | ||
Address string `json:"address"` | ||
Owner string `json:"owner"` | ||
} | ||
|
||
func lockHandler(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req lockReq | ||
|
||
if !rest.ReadRESTReq(w, r, cdc, &req) { | ||
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request") | ||
return | ||
} | ||
|
||
baseReq := req.BaseReq.Sanitize() | ||
if !baseReq.ValidateBasic(w) { | ||
return | ||
} | ||
|
||
addr, err := sdk.AccAddressFromBech32(req.Owner) | ||
if err != nil { | ||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
// create the message | ||
msg := witness.NewMsgLock(req.Data, req.Address, addr) | ||
err = msg.ValidateBasic() | ||
if err != nil { | ||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, baseReq, []sdk.Msg{msg}) | ||
} | ||
} |
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,24 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package witness | ||
|
||
import "github.com/cosmos/cosmos-sdk/codec" | ||
|
||
// RegisterCodec registers concrete types on the Amino codec | ||
func RegisterCodec(cdc *codec.Codec) { | ||
cdc.RegisterConcrete(MsgLock{}, "nameservice/SetName", nil) | ||
} |
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,40 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package witness | ||
|
||
import ( | ||
"reflect" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func NewHandler(keeper Keeper) sdk.Handler { | ||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { | ||
switch msg := msg.(type) { | ||
case MsgLock: | ||
return handleMsgLock(ctx, keeper, msg) | ||
default: | ||
errMsg := "Unrecognized lock Msg type: " + reflect.TypeOf(msg).Name() | ||
return sdk.ErrUnknownRequest(errMsg).Result() | ||
} | ||
} | ||
} | ||
|
||
// Handle lock message | ||
func handleMsgLock(ctx sdk.Context, keeper Keeper, msg MsgLock) sdk.Result { | ||
return sdk.Result{} | ||
} |
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,36 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package witness | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/gogo/protobuf/codec" | ||
) | ||
|
||
type Keeper struct { | ||
cdc *codec.Codec | ||
storeKey sdk.StoreKey | ||
|
||
//todo use cosmos erc20 keeper or client? | ||
} | ||
|
||
func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey) Keeper { | ||
return Keeper{ | ||
cdc: cdc, | ||
storeKey: storeKey, | ||
} | ||
} |
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,67 @@ | ||
/* | ||
* Copyright 2019 DE-labtory | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package witness | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type MsgLock struct { | ||
Data []byte | ||
Address string | ||
Owner sdk.AccAddress | ||
} | ||
|
||
func NewMsgLock(data []byte, address string, owner sdk.AccAddress) MsgLock { | ||
return MsgLock{ | ||
Address: address, | ||
Data: data, | ||
Owner: owner, | ||
} | ||
} | ||
|
||
func (msg MsgLock) Route() string { | ||
return "witness" | ||
} | ||
|
||
func (msg MsgLock) Type() string { | ||
return "lock" | ||
} | ||
|
||
func (msg MsgLock) ValidateBasic() sdk.Error { | ||
if msg.Owner.Empty() { | ||
return sdk.ErrInvalidAddress(msg.Owner.String()) | ||
} | ||
if len(msg.Address) == 0 || len(msg.Data) == 0 { | ||
return sdk.ErrUnknownRequest("Name and/or Value cannot be empty") | ||
} | ||
return nil | ||
} | ||
|
||
func (msg MsgLock) GetSignBytes() []byte { | ||
b, err := json.Marshal(msg) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return sdk.MustSortJSON(b) | ||
} | ||
|
||
func (msg MsgLock) GetSigners() []sdk.AccAddress { | ||
return []sdk.AccAddress{msg.Owner} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
data
args[1]
, notargs[0]
?You said
Use
is"lock [address] [data]"
.Then,
[address]
isargs[0]
,[data]
isargs[1]
.