diff --git a/.gitignore b/.gitignore index 689775f9e4..910d4b6fdc 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ genesis/beta genesis/gamma genesis/pylonsd +artifacts + diff --git a/Makefile b/Makefile index b6dc854bcf..659494b4be 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ VERSION := $(shell echo $(shell git describe --tags 2> /dev/null || echo "dev-$( COMMIT := $(shell git log -1 --format='%H') PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git) ARTIFACT_DIR := ./artifacts +LEDGER_ENABLED ?= true export GO111MODULE = on diff --git a/proto/pylons/redeem_info.proto b/proto/pylons/redeem_info.proto index 2e998fc36f..b8e44ea4ff 100644 --- a/proto/pylons/redeem_info.proto +++ b/proto/pylons/redeem_info.proto @@ -12,3 +12,10 @@ message RedeemInfo { string amount = 4 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];; string signature = 5; } + +message CreatePaymentAccount { + string address = 1; + string token = 2; + string signature = 3; +} + diff --git a/x/pylons/client/cli/gen_signed_api_token.go b/x/pylons/client/cli/gen_signed_api_token.go new file mode 100644 index 0000000000..0a5f69b9b3 --- /dev/null +++ b/x/pylons/client/cli/gen_signed_api_token.go @@ -0,0 +1,77 @@ +package cli + +import ( + "encoding/base64" + "errors" + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + + "github.com/Pylons-tech/pylons/x/pylons/types" +) + +var _ = strconv.Itoa(0) + +func CmdGenerateSignedAPIToken() *cobra.Command { + cmd := &cobra.Command{ + Use: "sign-api-token [api-token]", + Short: "generate signature for provided API token (used for external identification)", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + apiToken := args[0] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + if clientCtx.GetFromAddress().Empty() { + return errors.New("must use an identity to sign (use '--from' flag)") + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + sigBytes, err := SignAPIToken(txf, clientCtx.GetFromName(), apiToken) + if err != nil { + return err + } + + sigBase64 := base64.StdEncoding.EncodeToString(sigBytes) + + return printOutput(clientCtx, apiToken, sigBase64) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func SignAPIToken(txf tx.Factory, name, apiToken string) ([]byte, error) { + if txf.Keybase() == nil { + return nil, errors.New("keybase must be set prior to signing a transaction") + } + + bytesToSign := []byte(apiToken) + + // Sign those bytes + sigBytes, _, err := txf.Keybase().Sign(name, bytesToSign) + if err != nil { + return nil, err + } + + return sigBytes, nil +} + +func printOutput(ctx client.Context, token, sigBase64 string) error { + msg := types.CreatePaymentAccount{ + Address: ctx.GetFromAddress().String(), + Token: token, + Signature: sigBase64, + } + + return ctx.PrintProto(&msg) +} diff --git a/x/pylons/client/cli/tx.go b/x/pylons/client/cli/tx.go index 23ac2b7008..8891447abe 100644 --- a/x/pylons/client/cli/tx.go +++ b/x/pylons/client/cli/tx.go @@ -67,6 +67,8 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(CmdCreateCookbook()) cmd.AddCommand(CmdUpdateCookbook()) + cmd.AddCommand(CmdGenerateSignedAPIToken()) + return cmd } diff --git a/x/pylons/keeper/coins.go b/x/pylons/keeper/coins.go index fc305ef4bf..22abecee4c 100644 --- a/x/pylons/keeper/coins.go +++ b/x/pylons/keeper/coins.go @@ -58,7 +58,7 @@ func (k Keeper) MintCreditToAddr(ctx sdk.Context, addr sdk.AccAddress, amounts, } // send fees to the fee collector - err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, ppMacc, feesMacc, actualAmt) + err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, ppMacc, feesMacc, fees) if err != nil { return err } diff --git a/x/pylons/types/redeem_info.pb.go b/x/pylons/types/redeem_info.pb.go index e88ec8a907..9751c4f6be 100644 --- a/x/pylons/types/redeem_info.pb.go +++ b/x/pylons/types/redeem_info.pb.go @@ -5,12 +5,13 @@ package types import ( fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" + + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. @@ -93,32 +94,95 @@ func (m *RedeemInfo) GetSignature() string { return "" } +type CreatePaymentAccount struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` + Signature string `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *CreatePaymentAccount) Reset() { *m = CreatePaymentAccount{} } +func (m *CreatePaymentAccount) String() string { return proto.CompactTextString(m) } +func (*CreatePaymentAccount) ProtoMessage() {} +func (*CreatePaymentAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_6b1c4123658ff285, []int{1} +} +func (m *CreatePaymentAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CreatePaymentAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CreatePaymentAccount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CreatePaymentAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreatePaymentAccount.Merge(m, src) +} +func (m *CreatePaymentAccount) XXX_Size() int { + return m.Size() +} +func (m *CreatePaymentAccount) XXX_DiscardUnknown() { + xxx_messageInfo_CreatePaymentAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_CreatePaymentAccount proto.InternalMessageInfo + +func (m *CreatePaymentAccount) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *CreatePaymentAccount) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +func (m *CreatePaymentAccount) GetSignature() string { + if m != nil { + return m.Signature + } + return "" +} + func init() { proto.RegisterType((*RedeemInfo)(nil), "Pylonstech.pylons.pylons.RedeemInfo") + proto.RegisterType((*CreatePaymentAccount)(nil), "Pylonstech.pylons.pylons.CreatePaymentAccount") } func init() { proto.RegisterFile("pylons/redeem_info.proto", fileDescriptor_6b1c4123658ff285) } var fileDescriptor_6b1c4123658ff285 = []byte{ - // 274 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0xa8, 0xcc, 0xc9, - 0xcf, 0x2b, 0xd6, 0x2f, 0x4a, 0x4d, 0x49, 0x4d, 0xcd, 0x8d, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, - 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x08, 0x00, 0xcb, 0x94, 0xa4, 0x26, 0x67, 0xe8, 0x41, 0x14, - 0x41, 0x29, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0xb0, 0x22, 0x7d, 0x10, 0x0b, 0xa2, 0x5e, 0xe9, - 0x10, 0x23, 0x17, 0x57, 0x10, 0xd8, 0x14, 0xcf, 0xbc, 0xb4, 0x7c, 0x21, 0x3e, 0x2e, 0x26, 0x4f, - 0x17, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x26, 0x4f, 0x17, 0x21, 0x15, 0x2e, 0xde, 0x82, - 0xa2, 0xfc, 0xe4, 0xd4, 0xe2, 0xe2, 0xfc, 0x22, 0xbf, 0xc4, 0xdc, 0x54, 0x09, 0x26, 0xb0, 0x14, - 0xaa, 0xa0, 0x90, 0x04, 0x17, 0x7b, 0x62, 0x4a, 0x4a, 0x51, 0x6a, 0x71, 0xb1, 0x04, 0x33, 0x58, - 0x1e, 0xc6, 0x15, 0x72, 0xe3, 0x62, 0x4b, 0xcc, 0xcd, 0x2f, 0xcd, 0x2b, 0x91, 0x60, 0x01, 0x49, - 0x38, 0xe9, 0x9d, 0xb8, 0x27, 0xcf, 0x70, 0xeb, 0x9e, 0xbc, 0x5a, 0x7a, 0x66, 0x49, 0x46, 0x69, - 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0x31, 0x94, 0xd2, 0x2d, 0x4e, - 0xc9, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0xf3, 0xcc, 0x2b, 0x09, 0x82, 0xea, 0x16, 0x92, - 0xe1, 0xe2, 0x2c, 0xce, 0x4c, 0xcf, 0x4b, 0x2c, 0x29, 0x2d, 0x4a, 0x95, 0x60, 0x05, 0xdb, 0x81, - 0x10, 0x70, 0x72, 0x3b, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, - 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x1d, 0x24, - 0x7b, 0x20, 0x21, 0xa3, 0x0b, 0x0a, 0x1a, 0x7d, 0x68, 0xf8, 0x55, 0xc0, 0x18, 0x60, 0x1b, 0x93, - 0xd8, 0xc0, 0x61, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x7e, 0xea, 0x98, 0x8f, 0x5f, 0x01, - 0x00, 0x00, + // 314 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x51, 0xc1, 0x6a, 0x32, 0x31, + 0x10, 0xde, 0xe8, 0xaf, 0x3f, 0x06, 0xda, 0xc3, 0xe2, 0x21, 0x94, 0x12, 0x8b, 0x94, 0xd2, 0x43, + 0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, 0xcf, 0xb4, 0x70, 0x4b, 0x03, 0xac, 0xe1, 0x35, 0x7e, 0x0b, + 0xdd, 0x94, 0xb6, 0x1f, 0x0d, 0x08, 0x07, 0x23, 0xb1, 0x52, 0xa0, 0xdd, 0x83, 0x94, 0xbe, 0xeb, + 0x64, 0x2e, 0x52, 0x9d, 0xab, 0x4d, 0x1b, 0x0e, 0x17, 0xa0, 0x4b, 0x3f, 0x45, 0x52, 0x55, 0xa9, + 0xff, 0x51, 0xe9, 0x0f, 0xd7, 0x3b, 0x4e, 0x36, 0x3b, 0x4e, 0xbe, 0x77, 0x9c, 0xbc, 0xef, 0x79, + 0xb0, 0xd9, 0xf3, 0xe0, 0x73, 0xcf, 0x83, 0xe7, 0xbb, 0x13, 0x37, 0xc5, 0xfe, 0x7b, 0x87, 0x03, + 0xc4, 0xe5, 0x95, 0xde, 0x8e, 0x81, 0xf7, 0x35, 0x69, 0xfa, 0xcd, 0xdf, 0xff, 0x04, 0x00, 0x00, + 0xff, 0xff, 0x1e, 0xe1, 0x20, 0x79, 0xc5, 0x01, 0x00, 0x00, } func (m *RedeemInfo) Marshal() (dAtA []byte, err error) { @@ -182,6 +246,50 @@ func (m *RedeemInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CreatePaymentAccount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CreatePaymentAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CreatePaymentAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintRedeemInfo(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x1a + } + if len(m.Token) > 0 { + i -= len(m.Token) + copy(dAtA[i:], m.Token) + i = encodeVarintRedeemInfo(dAtA, i, uint64(len(m.Token))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintRedeemInfo(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintRedeemInfo(dAtA []byte, offset int, v uint64) int { offset -= sovRedeemInfo(v) base := offset @@ -220,6 +328,27 @@ func (m *RedeemInfo) Size() (n int) { return n } +func (m *CreatePaymentAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovRedeemInfo(uint64(l)) + } + l = len(m.Token) + if l > 0 { + n += 1 + l + sovRedeemInfo(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovRedeemInfo(uint64(l)) + } + return n +} + func sovRedeemInfo(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -438,6 +567,152 @@ func (m *RedeemInfo) Unmarshal(dAtA []byte) error { } return nil } +func (m *CreatePaymentAccount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRedeemInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CreatePaymentAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CreatePaymentAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRedeemInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRedeemInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRedeemInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRedeemInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRedeemInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRedeemInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Token = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRedeemInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRedeemInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRedeemInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRedeemInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRedeemInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipRedeemInfo(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0