github.com/lino-network/lino@v0.6.11/x/developer/types/msg.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"unicode/utf8"
     6  
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  
     9  	"github.com/lino-network/lino/types"
    10  )
    11  
    12  // DeveloperRegisterMsg - register developer on blockchain
    13  type DeveloperRegisterMsg struct {
    14  	Username    types.AccountKey `json:"username"`
    15  	Website     string           `json:"website"`
    16  	Description string           `json:"description"`
    17  	AppMetaData string           `json:"app_meta_data"`
    18  }
    19  
    20  var _ types.Msg = DeveloperRegisterMsg{}
    21  
    22  // DeveloperRegisterMsg Msg Implementations
    23  func NewDeveloperRegisterMsg(developer string, website string, description string, appMetaData string) DeveloperRegisterMsg {
    24  	return DeveloperRegisterMsg{
    25  		Username:    types.AccountKey(developer),
    26  		Website:     website,
    27  		Description: description,
    28  		AppMetaData: appMetaData,
    29  	}
    30  }
    31  
    32  // Route - implements sdk.Msg
    33  func (msg DeveloperRegisterMsg) Route() string { return RouterKey }
    34  
    35  // Type - implements sdk.Msg
    36  func (msg DeveloperRegisterMsg) Type() string { return "DeveloperRegisterMsg" }
    37  
    38  // ValidateBasic - implements sdk.Msg
    39  func (msg DeveloperRegisterMsg) ValidateBasic() sdk.Error {
    40  	if !msg.Username.IsValid() {
    41  		return ErrInvalidUsername()
    42  	}
    43  
    44  	if len(msg.Website) > types.MaximumLengthOfDeveloperWebsite {
    45  		return ErrInvalidWebsite()
    46  	}
    47  
    48  	if utf8.RuneCountInString(msg.Description) > types.MaximumLengthOfDeveloperDesctiption {
    49  		return ErrInvalidDescription()
    50  	}
    51  
    52  	if utf8.RuneCountInString(msg.AppMetaData) > types.MaximumLengthOfAppMetadata {
    53  		return ErrInvalidAppMetadata()
    54  	}
    55  	return nil
    56  }
    57  
    58  func (msg DeveloperRegisterMsg) String() string {
    59  	return fmt.Sprintf("DeveloperRegisterMsg{%s}", msg.Username)
    60  }
    61  
    62  func (msg DeveloperRegisterMsg) GetPermission() types.Permission {
    63  	return types.TransactionPermission
    64  }
    65  
    66  func (msg DeveloperRegisterMsg) GetSignBytes() []byte {
    67  	return getSignBytes(msg)
    68  }
    69  
    70  // GetSigners - implements sdk.Msg
    71  func (msg DeveloperRegisterMsg) GetSigners() []sdk.AccAddress {
    72  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
    73  }
    74  
    75  func (msg DeveloperRegisterMsg) GetConsumeAmount() types.Coin {
    76  	return types.NewCoinFromInt64(0)
    77  }
    78  
    79  // DeveloperUpdateMsg - update developer info on blockchain
    80  type DeveloperUpdateMsg struct {
    81  	Username    types.AccountKey `json:"username"`
    82  	Website     string           `json:"website"`
    83  	Description string           `json:"description"`
    84  	AppMetaData string           `json:"app_meta_data"`
    85  }
    86  
    87  var _ types.Msg = DeveloperUpdateMsg{}
    88  
    89  // NewDeveloperUpdateMsg - new DeveloperUpdateMsg
    90  func NewDeveloperUpdateMsg(developer string, website string, description string, appMetaData string) DeveloperUpdateMsg {
    91  	return DeveloperUpdateMsg{
    92  		Username:    types.AccountKey(developer),
    93  		Website:     website,
    94  		Description: description,
    95  		AppMetaData: appMetaData,
    96  	}
    97  }
    98  
    99  // Route - implements sdk.Msg
   100  func (msg DeveloperUpdateMsg) Route() string { return RouterKey }
   101  
   102  // Type - implements sdk.Msg
   103  func (msg DeveloperUpdateMsg) Type() string { return "DeveloperUpdateMsg" }
   104  
   105  // ValidateBasic - implements sdk.Msg
   106  func (msg DeveloperUpdateMsg) ValidateBasic() sdk.Error {
   107  	if !msg.Username.IsValid() {
   108  		return ErrInvalidUsername()
   109  	}
   110  
   111  	if len(msg.Website) > types.MaximumLengthOfDeveloperWebsite {
   112  		return ErrInvalidWebsite()
   113  	}
   114  
   115  	if utf8.RuneCountInString(msg.Description) > types.MaximumLengthOfDeveloperDesctiption {
   116  		return ErrInvalidDescription()
   117  	}
   118  
   119  	if utf8.RuneCountInString(msg.AppMetaData) > types.MaximumLengthOfAppMetadata {
   120  		return ErrInvalidAppMetadata()
   121  	}
   122  	return nil
   123  }
   124  
   125  func (msg DeveloperUpdateMsg) String() string {
   126  	return fmt.Sprintf(
   127  		"DeveloperUpdateMsg{Username:%v, Website:%v, Description:%v, Metadata:%v}",
   128  		msg.Username, msg.Website, msg.Description, msg.AppMetaData)
   129  }
   130  
   131  func (msg DeveloperUpdateMsg) GetPermission() types.Permission {
   132  	return types.TransactionPermission
   133  }
   134  
   135  func (msg DeveloperUpdateMsg) GetSignBytes() []byte {
   136  	return getSignBytes(msg)
   137  }
   138  
   139  // GetSigners - implements sdk.Msg
   140  func (msg DeveloperUpdateMsg) GetSigners() []sdk.AccAddress {
   141  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
   142  }
   143  
   144  // GetConsumeAmount - implements types.Msg
   145  func (msg DeveloperUpdateMsg) GetConsumeAmount() types.Coin {
   146  	return types.NewCoinFromInt64(0)
   147  }
   148  
   149  // DeveloperRevokeMsg - revoke developer on blockchain
   150  type DeveloperRevokeMsg struct {
   151  	Username types.AccountKey `json:"username"`
   152  }
   153  
   154  var _ types.Msg = DeveloperRevokeMsg{}
   155  
   156  // DeveloperRevokeMsg Msg Implementations
   157  func NewDeveloperRevokeMsg(developer string) DeveloperRevokeMsg {
   158  	return DeveloperRevokeMsg{
   159  		Username: types.AccountKey(developer),
   160  	}
   161  }
   162  
   163  // Route - implements sdk.Msg
   164  func (msg DeveloperRevokeMsg) Route() string { return RouterKey }
   165  
   166  // Type - implements sdk.Msg
   167  func (msg DeveloperRevokeMsg) Type() string { return "DeveloperRevokeMsg" }
   168  
   169  func (msg DeveloperRevokeMsg) ValidateBasic() sdk.Error {
   170  	if !msg.Username.IsValid() {
   171  		return ErrInvalidUsername()
   172  	}
   173  	return nil
   174  }
   175  
   176  func (msg DeveloperRevokeMsg) String() string {
   177  	return fmt.Sprintf("DeveloperRevokeMsg{Username:%v}", msg.Username)
   178  }
   179  
   180  func (msg DeveloperRevokeMsg) GetPermission() types.Permission {
   181  	return types.TransactionPermission
   182  }
   183  
   184  // GetSignBytes - implements sdk.Msg
   185  func (msg DeveloperRevokeMsg) GetSignBytes() []byte {
   186  	return getSignBytes(msg)
   187  }
   188  
   189  // GetSigners - implements sdk.Msg
   190  func (msg DeveloperRevokeMsg) GetSigners() []sdk.AccAddress {
   191  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
   192  }
   193  
   194  // GetConsumeAmount - implements types.Msg
   195  func (msg DeveloperRevokeMsg) GetConsumeAmount() types.Coin {
   196  	return types.NewCoinFromInt64(0)
   197  }
   198  
   199  const (
   200  	// IDA price's unit is 1/10 usd cent. range: [0.001USD, 1USD]
   201  	IDAPriceMin = 1
   202  	IDAPriceMax = 1000
   203  )
   204  
   205  // IDAIssueMsg - IDA issue message.
   206  type IDAIssueMsg struct {
   207  	Username types.AccountKey `json:"username"`
   208  	// IDAName  string           `json:"ida_name"`
   209  	IDAPrice int64 `json:"ida_price"`
   210  }
   211  
   212  var _ types.Msg = IDAIssueMsg{}
   213  
   214  // Route - implements sdk.Msg
   215  func (msg IDAIssueMsg) Route() string { return RouterKey }
   216  
   217  // Type - implements sdk.Msg
   218  func (msg IDAIssueMsg) Type() string { return "IDAIssueMsg" }
   219  
   220  // ValidateBasic - implements sdk.Msg
   221  func (msg IDAIssueMsg) ValidateBasic() sdk.Error {
   222  	if !msg.Username.IsValid() {
   223  		return ErrInvalidUsername()
   224  	}
   225  	// if len(msg.IDAName) < 3 || len(msg.IDAName) > 10 {
   226  	// 	return ErrInvalidIDAName()
   227  	// }
   228  	// if !allUppercaseLetter(msg.IDAName) {
   229  	// 	return ErrInvalidIDAName()
   230  	// }
   231  	if !(msg.IDAPrice >= IDAPriceMin && msg.IDAPrice <= IDAPriceMax) {
   232  		return ErrInvalidIDAPrice()
   233  	}
   234  	return nil
   235  }
   236  
   237  func (msg IDAIssueMsg) String() string {
   238  	return fmt.Sprintf("IDAIssueMsg{%s, %d}", msg.Username, msg.IDAPrice)
   239  }
   240  
   241  func (msg IDAIssueMsg) GetPermission() types.Permission {
   242  	return types.TransactionPermission
   243  }
   244  
   245  // GetSignBytes - implements sdk.Msg
   246  func (msg IDAIssueMsg) GetSignBytes() []byte {
   247  	return getSignBytes(msg)
   248  }
   249  
   250  // GetSigners - implements sdk.Msg
   251  func (msg IDAIssueMsg) GetSigners() []sdk.AccAddress {
   252  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
   253  }
   254  
   255  // GetConsumeAmount - implements types.Msg
   256  func (msg IDAIssueMsg) GetConsumeAmount() types.Coin {
   257  	return types.NewCoinFromInt64(0)
   258  }
   259  
   260  // IDAMintMsg - Mint more IDA from user pool.
   261  type IDAMintMsg struct {
   262  	Username types.AccountKey `json:"username"`
   263  	Amount   types.LNO        `json:"amount"`
   264  }
   265  
   266  var _ types.Msg = IDAMintMsg{}
   267  
   268  // Route - implements sdk.Msg
   269  func (msg IDAMintMsg) Route() string { return RouterKey }
   270  
   271  // Type - implements sdk.Msg
   272  func (msg IDAMintMsg) Type() string { return "IDAMintMsg" }
   273  
   274  // ValidateBasic - implements sdk.Msg
   275  func (msg IDAMintMsg) ValidateBasic() sdk.Error {
   276  	if !msg.Username.IsValid() {
   277  		return ErrInvalidUsername()
   278  	}
   279  	_, err := types.LinoToCoin(msg.Amount)
   280  	if err != nil {
   281  		return err
   282  	}
   283  	return nil
   284  }
   285  
   286  func (msg IDAMintMsg) String() string {
   287  	return fmt.Sprintf("IDAMintMsg{username:%v, amount:%v}", msg.Username, msg.Amount)
   288  }
   289  
   290  func (msg IDAMintMsg) GetPermission() types.Permission {
   291  	return types.TransactionPermission
   292  }
   293  
   294  // GetSignBytes - implements sdk.Msg
   295  func (msg IDAMintMsg) GetSignBytes() []byte {
   296  	return getSignBytes(msg)
   297  }
   298  
   299  // GetSigners - implements sdk.Msg
   300  func (msg IDAMintMsg) GetSigners() []sdk.AccAddress {
   301  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
   302  }
   303  
   304  // GetConsumeAmount - implements types.Msg
   305  func (msg IDAMintMsg) GetConsumeAmount() types.Coin {
   306  	return types.NewCoinFromInt64(0)
   307  }
   308  
   309  // IDAConvertFromLinoMsg - convert from lino to ida.
   310  type IDAConvertFromLinoMsg struct {
   311  	Username types.AccountKey `json:"username"`
   312  	App      types.AccountKey `json:"app"`
   313  	Amount   types.LNO        `json:"amount"`
   314  }
   315  
   316  var _ types.Msg = IDAConvertFromLinoMsg{}
   317  
   318  // Route - implements sdk.Msg
   319  func (msg IDAConvertFromLinoMsg) Route() string { return RouterKey }
   320  
   321  // Type - implements sdk.Msg
   322  func (msg IDAConvertFromLinoMsg) Type() string { return "IDAConvertFromLinoMsg" }
   323  
   324  // ValidateBasic - implements sdk.Msg
   325  func (msg IDAConvertFromLinoMsg) ValidateBasic() sdk.Error {
   326  	if !msg.Username.IsValid() || !msg.App.IsValid() {
   327  		return ErrInvalidUsername()
   328  	}
   329  	_, err := types.LinoToCoin(msg.Amount)
   330  	if err != nil {
   331  		return err
   332  	}
   333  	return nil
   334  }
   335  
   336  func (msg IDAConvertFromLinoMsg) String() string {
   337  	return fmt.Sprintf("IDAConvertFromLinoMsg{user:%s, app:%s, amount:%s}",
   338  		msg.Username, msg.App, msg.Amount)
   339  }
   340  
   341  func (msg IDAConvertFromLinoMsg) GetPermission() types.Permission {
   342  	return types.TransactionPermission
   343  }
   344  
   345  // GetSignBytes - implements sdk.Msg
   346  func (msg IDAConvertFromLinoMsg) GetSignBytes() []byte {
   347  	return getSignBytes(msg)
   348  }
   349  
   350  // GetSigners - implements sdk.Msg
   351  func (msg IDAConvertFromLinoMsg) GetSigners() []sdk.AccAddress {
   352  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
   353  }
   354  
   355  // GetConsumeAmount - implements types.Msg
   356  func (msg IDAConvertFromLinoMsg) GetConsumeAmount() types.Coin {
   357  	return types.NewCoinFromInt64(0)
   358  }
   359  
   360  // IDATransferMsg - Transfer IDA.
   361  type IDATransferMsg struct {
   362  	App    types.AccountKey `json:"app"`
   363  	Amount types.IDAStr     `json:"amount"`
   364  	From   types.AccountKey `json:"from"`
   365  	To     types.AccountKey `json:"to"`
   366  	Signer types.AccountKey `json:"singer"`
   367  	Memo   string           `json:"memo"`
   368  }
   369  
   370  var _ types.Msg = IDATransferMsg{}
   371  
   372  // Route - implements sdk.Msg
   373  func (msg IDATransferMsg) Route() string { return RouterKey }
   374  
   375  // Type - implements sdk.Msg
   376  func (msg IDATransferMsg) Type() string { return "IDATransferMsg" }
   377  
   378  // ValidateBasic - implements sdk.Msg
   379  func (msg IDATransferMsg) ValidateBasic() sdk.Error {
   380  	if len(msg.Memo) > types.MaximumMemoLength {
   381  		return ErrInvalidMemo()
   382  	}
   383  
   384  	if !msg.App.IsValid() ||
   385  		!msg.From.IsValid() ||
   386  		!msg.To.IsValid() ||
   387  		!msg.Signer.IsValid() {
   388  		return ErrInvalidUsername()
   389  	}
   390  	if msg.From == msg.To {
   391  		return ErrIDATransferSelf()
   392  	}
   393  	if !(msg.From == msg.App || msg.To == msg.App) {
   394  		return ErrInvalidTransferTarget()
   395  	}
   396  	_, err := msg.Amount.ToMiniIDA()
   397  	if err != nil {
   398  		return err
   399  	}
   400  	return nil
   401  }
   402  
   403  func (msg IDATransferMsg) String() string {
   404  	return fmt.Sprintf("IDATransferMsg{%v, %v, %v, %v}", msg.App, msg.Amount, msg.From, msg.To)
   405  }
   406  
   407  func (msg IDATransferMsg) GetPermission() types.Permission {
   408  	return types.AppOrAffiliatedPermission
   409  }
   410  
   411  // GetSignBytes - implements sdk.Msg
   412  func (msg IDATransferMsg) GetSignBytes() []byte {
   413  	return getSignBytes(msg)
   414  }
   415  
   416  // GetSigners - implements sdk.Msg
   417  func (msg IDATransferMsg) GetSigners() []sdk.AccAddress {
   418  	return []sdk.AccAddress{sdk.AccAddress(msg.Signer)}
   419  }
   420  
   421  // GetConsumeAmount - implements types.Msg
   422  func (msg IDATransferMsg) GetConsumeAmount() types.Coin {
   423  	return types.NewCoinFromInt64(0)
   424  }
   425  
   426  // IDAAuthorizeMsg - update app's permission of IDA of the user.
   427  type IDAAuthorizeMsg struct {
   428  	Username types.AccountKey `json:"username"`
   429  	App      types.AccountKey `json:"app"`
   430  	Activate bool             `json:"activate"`
   431  }
   432  
   433  var _ types.Msg = IDAAuthorizeMsg{}
   434  
   435  // Route - implements sdk.Msg
   436  func (msg IDAAuthorizeMsg) Route() string { return RouterKey }
   437  
   438  // Type - implements sdk.Msg
   439  func (msg IDAAuthorizeMsg) Type() string { return "IDAAuthorizeMsg" }
   440  
   441  // ValidateBasic - implements sdk.Msg
   442  func (msg IDAAuthorizeMsg) ValidateBasic() sdk.Error {
   443  	if !msg.Username.IsValid() || !msg.App.IsValid() {
   444  		return ErrInvalidUsername()
   445  	}
   446  	if msg.App == msg.Username {
   447  		return ErrInvalidIDAAuth()
   448  	}
   449  	return nil
   450  }
   451  
   452  func (msg IDAAuthorizeMsg) String() string {
   453  	return fmt.Sprintf("IDAAuthorizeMsg{}")
   454  }
   455  
   456  func (msg IDAAuthorizeMsg) GetPermission() types.Permission {
   457  	return types.TransactionPermission
   458  }
   459  
   460  // GetSignBytes - implements sdk.Msg
   461  func (msg IDAAuthorizeMsg) GetSignBytes() []byte {
   462  	return getSignBytes(msg)
   463  }
   464  
   465  // GetSigners - implements sdk.Msg
   466  func (msg IDAAuthorizeMsg) GetSigners() []sdk.AccAddress {
   467  	return []sdk.AccAddress{sdk.AccAddress(msg.Username)}
   468  }
   469  
   470  // GetConsumeAmount - implements types.Msg
   471  func (msg IDAAuthorizeMsg) GetConsumeAmount() types.Coin {
   472  	return types.NewCoinFromInt64(0)
   473  }
   474  
   475  // UpdateAffiliatedMsg - update affiliate accounts.
   476  type UpdateAffiliatedMsg struct {
   477  	App      types.AccountKey `json:"app"`
   478  	Username types.AccountKey `json:"username"`
   479  	Activate bool             `json:"activate"`
   480  }
   481  
   482  var _ types.Msg = UpdateAffiliatedMsg{}
   483  
   484  // Route - implements sdk.Msg
   485  func (msg UpdateAffiliatedMsg) Route() string { return RouterKey }
   486  
   487  // Type - implements sdk.Msg
   488  func (msg UpdateAffiliatedMsg) Type() string { return "UpdateAffiliatedMsg" }
   489  
   490  // ValidateBasic - implements sdk.Msg
   491  func (msg UpdateAffiliatedMsg) ValidateBasic() sdk.Error {
   492  	if !msg.App.IsValid() || !msg.Username.IsValid() {
   493  		return ErrInvalidUsername()
   494  	}
   495  	return nil
   496  }
   497  
   498  func (msg UpdateAffiliatedMsg) String() string {
   499  	return fmt.Sprintf("UpdateAffiliatedMsg{}")
   500  }
   501  
   502  func (msg UpdateAffiliatedMsg) GetPermission() types.Permission {
   503  	return types.TransactionPermission
   504  }
   505  
   506  // GetSignBytes - implements sdk.Msg
   507  func (msg UpdateAffiliatedMsg) GetSignBytes() []byte {
   508  	return getSignBytes(msg)
   509  }
   510  
   511  // GetSigners - implements sdk.Msg
   512  func (msg UpdateAffiliatedMsg) GetSigners() []sdk.AccAddress {
   513  	return []sdk.AccAddress{sdk.AccAddress(msg.App)}
   514  }
   515  
   516  // GetConsumeAmount - implements types.Msg
   517  func (msg UpdateAffiliatedMsg) GetConsumeAmount() types.Coin {
   518  	return types.NewCoinFromInt64(0)
   519  }
   520  
   521  // utils
   522  func getSignBytes(msg sdk.Msg) []byte {
   523  	return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
   524  }
   525  
   526  // func allUppercaseLetter(s string) bool {
   527  // 	for _, v := range s {
   528  // 		if !(v >= 'A' && v <= 'Z') {
   529  // 			return false
   530  // 		}
   531  // 	}
   532  // 	return true
   533  // }