MCPcopy
hub / github.com/canopy-network/canopy / CheckBasic

Method CheckBasic

lib/tx.go:83–131  ·  view source on GitHub ↗

TRANSACTION CODE BELOW CheckBasic() is a stateless validation function for a Transaction object

()

Source from the content-addressed store, hash-verified

81
82// CheckBasic() is a stateless validation function for a Transaction object
83func (x *Transaction) CheckBasic() ErrorI {
84 // if the transaction is empty
85 if x == nil {
86 // exit with empty error
87 return ErrEmptyTransaction()
88 }
89 // if the payload is empty
90 if x.Msg == nil {
91 // exit with empty payload error
92 return ErrEmptyMessage()
93 }
94 // if the message type is empty
95 if x.MessageType == "" {
96 // exit with empty payload name error
97 return ErrUnknownMessageName(x.MessageType)
98 }
99 // if any parts of the signature is empty
100 if x.Signature == nil || x.Signature.Signature == nil || x.Signature.PublicKey == nil {
101 // exit with empty signature error
102 return ErrEmptySignature()
103 }
104 // if the created height is empty
105 if x.CreatedHeight == 0 {
106 // exit with created height error
107 return ErrInvalidTxHeight()
108 }
109 // if the time is empty
110 if x.Time == 0 {
111 // exit with invalid time error
112 return ErrInvalidTxTime()
113 }
114 // if the memo is too long
115 if len(x.Memo) > 200 {
116 // exit with 'memo too long' error
117 return ErrInvalidMemo()
118 }
119 // if the network id is empty
120 if x.NetworkId == 0 {
121 // exit with empty network id error
122 return ErrNilNetworkID()
123 }
124 // if the chain id is empty
125 if x.ChainId == 0 {
126 // exit with empty chain id error
127 return ErrEmptyChainId()
128 }
129 // exit with no error
130 return nil
131}
132
133// GetHash() returns the cryptographic hash of the Transaction
134func (x *Transaction) GetHash() ([]byte, ErrorI) {

Callers

nothing calls this directly

Calls 9

ErrEmptyTransactionFunction · 0.85
ErrUnknownMessageNameFunction · 0.85
ErrInvalidTxHeightFunction · 0.85
ErrInvalidTxTimeFunction · 0.85
ErrInvalidMemoFunction · 0.85
ErrNilNetworkIDFunction · 0.85
ErrEmptyChainIdFunction · 0.85
ErrEmptyMessageFunction · 0.70
ErrEmptySignatureFunction · 0.70

Tested by

no test coverage detected