github.com/annchain/OG@v0.0.9/og/types/txbase.go (about) 1 package types 2 3 import ( 4 "github.com/annchain/OG/arefactor/og/types" 5 "strings" 6 ) 7 8 // Here indicates what fields should be concerned during hash calculation and signature generation 9 // | | | Signature target | NonceHash(Slow) | TxHash(Fast) | 10 // |------|-------------------|------------------|---------------------|-----------------| 11 // | Base | ParentsHash | | | 1 | 12 // | Base | Height | | | | 13 // | Base | PublicKey | | 1 | 1 (nonce hash) | 14 // | Base | Signature | | 1 | 1 (nonce hash) | 15 // | Base | MinedNonce | | 1 | 1 (nonce hash) | 16 // | Base | AccountNonce | 1 | | | 17 // | Tx | From | 1 | | | 18 // | Tx | To | 1 | | | 19 // | Tx | Value | 1 | | | 20 // | Tx | Data | 1 | | | 21 // | Seq | MyIndex | 1 | | | 22 // | Seq | ContractHashOrder | 1 | | | 23 24 type TxBase struct { 25 // Type TxBaseType 26 Hash types.Hash 27 ParentsHash types.Hashes 28 // AccountNonce uint64 29 Height uint64 30 // PublicKey ogcrypto.PublicKey // 31 // Signature hexutil.KeyBytes 32 // MineNonce uint64 33 // Weight uint64 34 // inValid bool 35 // Version byte 36 // //verified VerifiedType 37 } 38 39 type Txis []Txi 40 41 func (t Txis) String() string { 42 var strs []string 43 for _, v := range t { 44 strs = append(strs, v.String()) 45 } 46 return strings.Join(strs, ", ") 47 } 48 49 func (t Txis) Len() int { 50 return len(t) 51 } 52 53 func (t Txis) Less(i, j int) bool { 54 if t[i].GetWeight() < t[j].GetWeight() { 55 return true 56 } 57 if t[i].GetWeight() > t[j].GetWeight() { 58 return false 59 } 60 //if t[i].GetNonce() < t[j].GetNonce() { 61 // return true 62 //} 63 //if t[i].GetNonce() > t[j].GetNonce() { 64 // return false 65 //} 66 if t[i].GetHash().Cmp(t[j].GetHash()) < 0 { 67 return true 68 } 69 return false 70 } 71 72 func (t Txis) Swap(i, j int) { 73 t[i], t[j] = t[j], t[i] 74 }