github.com/igggame/nebulas-go@v2.1.0+incompatible/core/transaction_dip_payload.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 core 20 21 import ( 22 "encoding/json" 23 24 "github.com/nebulasio/go-nebulas/util" 25 ) 26 27 // DipPayload carry ir data 28 type DipPayload struct { 29 StartHeight uint64 30 EndHeight uint64 31 Version uint64 32 Contract string 33 } 34 35 // LoadDipPayload from bytes 36 func LoadDipPayload(bytes []byte) (*DipPayload, error) { 37 payload := &DipPayload{} 38 if err := json.Unmarshal(bytes, payload); err != nil { 39 return nil, ErrInvalidArgument 40 } 41 return NewDipPayload(payload.StartHeight, payload.EndHeight, payload.Version, payload.Contract) 42 } 43 44 // NewDipPayload with data 45 func NewDipPayload(start, end, version uint64, contract string) (*DipPayload, error) { 46 if end < start { 47 return nil, ErrInvalidArgument 48 } 49 return &DipPayload{ 50 StartHeight: start, 51 EndHeight: end, 52 Version: version, 53 Contract: contract, 54 }, nil 55 } 56 57 // ToBytes serialize payload 58 func (payload *DipPayload) ToBytes() ([]byte, error) { 59 return json.Marshal(payload) 60 } 61 62 // BaseGasCount returns base gas count 63 func (payload *DipPayload) BaseGasCount() *util.Uint128 { 64 return util.NewUint128() 65 } 66 67 // Execute the payload in tx 68 func (payload *DipPayload) Execute(limitedGas *util.Uint128, tx *Transaction, block *Block, ws WorldState) (*util.Uint128, string, error) { 69 if block == nil || tx == nil { 70 return util.NewUint128(), "", ErrNilArgument 71 } 72 73 return util.NewUint128(), "", nil 74 }