github.com/igggame/nebulas-go@v2.1.0+incompatible/nip/dip/types.go (about)

     1  // Copyright (C) 2017 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  
    19  package dip
    20  
    21  import (
    22  	"encoding/json"
    23  	"errors"
    24  
    25  	"github.com/nebulasio/go-nebulas/core"
    26  	"github.com/nebulasio/go-nebulas/neblet/pb"
    27  )
    28  
    29  // Error types
    30  var (
    31  	ErrDipNotFound = errors.New("dip not found")
    32  
    33  	ErrInvalidDipAddress                    = errors.New("invalid dip reward address")
    34  	ErrUnsupportedTransactionFromDipAddress = errors.New("unsupported transaction from dip address")
    35  )
    36  
    37  // const types
    38  const (
    39  	CacheSize = 128
    40  
    41  	// DipRewardAddressPrivate dip reward rewardAddress:n1c6y4ctkMeZk624QWBTXuywmNpCWmJZiBq
    42  	DipRewardAddressPrivate = "42f0c8b5feb72301619046ca87e6cf2c605e94dae0e24c9cb3a0101dbb60337c"
    43  	// DipRewardAddressPassphrase
    44  	DipRewardAddressPassphrase = "passphrase"
    45  )
    46  
    47  type Neblet interface {
    48  	Config() *nebletpb.Config
    49  	AccountManager() core.AccountManager
    50  	BlockChain() *core.BlockChain
    51  }
    52  
    53  type DipReward struct {
    54  	DipRewards []string `json:"dip_rewards"`
    55  }
    56  
    57  type DIPItem struct {
    58  	Address  string `json:"address"`
    59  	Contract string `json:"contract"`
    60  	Reward   string `json:"reward"`
    61  }
    62  
    63  type DIPData struct {
    64  	StartHeight uint64     `json:"start_height,string"`
    65  	EndHeight   uint64     `json:"end_height,string"`
    66  	Version     uint64     `json:"version,string"`
    67  	Dips        []*DIPItem `json:"dips"`
    68  	Err         string     `json:"err"`
    69  }
    70  
    71  // ToBytes serialize data
    72  func (d *DIPData) ToBytes() ([]byte, error) {
    73  	return json.Marshal(d)
    74  }
    75  
    76  // FromBytes
    77  func (d *DIPData) FromBytes(data []byte) error {
    78  	if err := json.Unmarshal(data, d); err != nil {
    79  		return err
    80  	}
    81  	return nil
    82  }