github.com/snowblossomcoin/go-ethereum@v1.9.25/signer/core/types.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package core 18 19 import ( 20 "encoding/json" 21 "fmt" 22 "math/big" 23 "strings" 24 25 "github.com/ethereum/go-ethereum/common" 26 "github.com/ethereum/go-ethereum/common/hexutil" 27 "github.com/ethereum/go-ethereum/core/types" 28 ) 29 30 type ValidationInfo struct { 31 Typ string `json:"type"` 32 Message string `json:"message"` 33 } 34 type ValidationMessages struct { 35 Messages []ValidationInfo 36 } 37 38 const ( 39 WARN = "WARNING" 40 CRIT = "CRITICAL" 41 INFO = "Info" 42 ) 43 44 func (vs *ValidationMessages) Crit(msg string) { 45 vs.Messages = append(vs.Messages, ValidationInfo{CRIT, msg}) 46 } 47 func (vs *ValidationMessages) Warn(msg string) { 48 vs.Messages = append(vs.Messages, ValidationInfo{WARN, msg}) 49 } 50 func (vs *ValidationMessages) Info(msg string) { 51 vs.Messages = append(vs.Messages, ValidationInfo{INFO, msg}) 52 } 53 54 /// getWarnings returns an error with all messages of type WARN of above, or nil if no warnings were present 55 func (v *ValidationMessages) getWarnings() error { 56 var messages []string 57 for _, msg := range v.Messages { 58 if msg.Typ == WARN || msg.Typ == CRIT { 59 messages = append(messages, msg.Message) 60 } 61 } 62 if len(messages) > 0 { 63 return fmt.Errorf("validation failed: %s", strings.Join(messages, ",")) 64 } 65 return nil 66 } 67 68 // SendTxArgs represents the arguments to submit a transaction 69 type SendTxArgs struct { 70 From common.MixedcaseAddress `json:"from"` 71 To *common.MixedcaseAddress `json:"to"` 72 Gas hexutil.Uint64 `json:"gas"` 73 GasPrice hexutil.Big `json:"gasPrice"` 74 Value hexutil.Big `json:"value"` 75 Nonce hexutil.Uint64 `json:"nonce"` 76 // We accept "data" and "input" for backwards-compatibility reasons. 77 Data *hexutil.Bytes `json:"data"` 78 Input *hexutil.Bytes `json:"input,omitempty"` 79 } 80 81 func (args SendTxArgs) String() string { 82 s, err := json.Marshal(args) 83 if err == nil { 84 return string(s) 85 } 86 return err.Error() 87 } 88 89 func (args *SendTxArgs) toTransaction() *types.Transaction { 90 var input []byte 91 if args.Data != nil { 92 input = *args.Data 93 } else if args.Input != nil { 94 input = *args.Input 95 } 96 if args.To == nil { 97 return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(&args.GasPrice), input) 98 } 99 return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input) 100 }