Sitelet https://github.com/DAD-Chain/dad-go/commit/058b0130daf9ad1a4437a0a623d1bcef435c85ae
Skip to content

Commit 058b013

Browse files
go fmt project.
1 parent ace3aab commit 058b013

120 files changed

Lines changed: 752 additions & 717 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎account/client.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
const (
3030
DefaultBookKeeperCount = 4
31-
WalletFileName = "wallet.dat"
31+
WalletFileName = "wallet.dat"
3232
)
3333

3434
type Client interface {
@@ -39,20 +39,20 @@ type Client interface {
3939
}
4040

4141
type ClientImpl struct {
42-
mu sync.Mutex
42+
mu sync.Mutex
4343

44-
path string
45-
iv []byte
46-
masterKey []byte
44+
path string
45+
iv []byte
46+
masterKey []byte
4747

48-
accounts map[Uint160]*Account
49-
contracts map[Uint160]*ct.Contract
48+
accounts map[Uint160]*Account
49+
contracts map[Uint160]*ct.Contract
5050

5151
watchOnly []Uint160
5252
currentHeight uint32
5353

5454
FileStore
55-
isrunning bool
55+
isrunning bool
5656
}
5757

5858
//TODO: adjust contract folder structure
@@ -422,11 +422,11 @@ func (cl *ClientImpl) SaveAccount(ac *Account) error {
422422
return err
423423
}
424424
for i := 1; i <= 64; i++ {
425-
decryptedPrivateKey[i-1] = temp[i]
425+
decryptedPrivateKey[i - 1] = temp[i]
426426
}
427427

428428
for i := len(ac.PrivateKey) - 1; i >= 0; i-- {
429-
decryptedPrivateKey[96+i-len(ac.PrivateKey)] = ac.PrivateKey[i]
429+
decryptedPrivateKey[96 + i - len(ac.PrivateKey)] = ac.PrivateKey[i]
430430
}
431431

432432
encryptedPrivateKey, err := cl.EncryptPrivateKey(decryptedPrivateKey)

‎account/fileStore.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (cs *FileStore) readDB() ([]byte, error) {
5151

5252
func (cs *FileStore) writeDB(data []byte) error {
5353
var err error
54-
cs.file, err = os.OpenFile(cs.path, os.O_CREATE|os.O_WRONLY, 0666)
54+
cs.file, err = os.OpenFile(cs.path, os.O_CREATE | os.O_WRONLY, 0666)
5555
if err != nil {
5656
return err
5757
}
@@ -130,7 +130,7 @@ func (cs *FileStore) LoadStoredData(name string) ([]byte, error) {
130130
return hex.DecodeString(cs.fd.PasswordHash)
131131
}
132132

133-
return nil, NewDetailErr(errors.New("Can't find the key: "+name), ErrNoCode, "")
133+
return nil, NewDetailErr(errors.New("Can't find the key: " + name), ErrNoCode, "")
134134
}
135135

136136
func (cs *FileStore) SaveAccountData(pubkeyhash []byte, prikeyenc []byte) error {

‎cli/LevelDBQuery/LevelDBQuery.go‎

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/dad-go/crypto"
55
"github.com/dad-go/core/ledger"
66
"github.com/dad-go/core/store"
7-
."github.com/dad-go/common"
7+
. "github.com/dad-go/common"
88
"github.com/dad-go/common/log"
99
"encoding/hex"
1010
"os"
@@ -24,7 +24,7 @@ var Usage = func() {
2424
}
2525

2626
func DumpDB() {
27-
fd,_:=os.OpenFile("dump.txt",os.O_RDWR|os.O_CREATE,0644)
27+
fd, _ := os.OpenFile("dump.txt", os.O_RDWR | os.O_CREATE, 0644)
2828

2929
i := 0
3030
for (true) {
@@ -34,94 +34,92 @@ func DumpDB() {
3434
return
3535
}
3636

37-
block,err := ledger.DefaultLedger.Store.GetBlock(hash)
37+
block, err := ledger.DefaultLedger.Store.GetBlock(hash)
3838
if err != nil {
3939
fmt.Println("GetBlock() err!")
4040
return
4141
}
4242

43-
fd.Write( []byte(fmt.Sprintf("Block height: %d\n", block.Blockdata.Height)) )
43+
fd.Write([]byte(fmt.Sprintf("Block height: %d\n", block.Blockdata.Height)))
4444
h := block.Blockdata.Hash()
45-
fd.Write( []byte(fmt.Sprintf( "Block hash: %x\n", h.ToArray() )) )
46-
fd.Write( []byte(fmt.Sprintf( "Block timestamp: %d\n", block.Blockdata.Timestamp )) )
47-
fd.Write( []byte(fmt.Sprintf( "Block transactionsRoot :%x\n", block.Blockdata.TransactionsRoot )) )
48-
fd.Write( []byte(fmt.Sprintf( "Tx Len: %d\n", len(block.Transcations) )) )
45+
fd.Write([]byte(fmt.Sprintf("Block hash: %x\n", h.ToArray())))
46+
fd.Write([]byte(fmt.Sprintf("Block timestamp: %d\n", block.Blockdata.Timestamp)))
47+
fd.Write([]byte(fmt.Sprintf("Block transactionsRoot :%x\n", block.Blockdata.TransactionsRoot)))
48+
fd.Write([]byte(fmt.Sprintf("Tx Len: %d\n", len(block.Transcations))))
4949

50-
for k:=0; k<len(block.Transcations); k++ {
50+
for k := 0; k < len(block.Transcations); k++ {
5151
txhash := block.Transcations[k].Hash()
52-
fd.Write( []byte(fmt.Sprintf( "Tx hash: %x\n", txhash.ToArray() )) )
53-
fd.Write( []byte(fmt.Sprintf( "Tx Type: %x\n", block.Transcations[k].TxType )) )
52+
fd.Write([]byte(fmt.Sprintf("Tx hash: %x\n", txhash.ToArray())))
53+
fd.Write([]byte(fmt.Sprintf("Tx Type: %x\n", block.Transcations[k].TxType)))
5454
}
5555

56-
fd.Write( []byte("\n") )
56+
fd.Write([]byte("\n"))
5757
i ++
5858
}
5959

6060
fd.Close()
6161
}
6262

63-
6463
func GetBlock(hash string) {
65-
bhash,err := hex.DecodeString(hash)
66-
uhash,err := Uint256ParseFromBytes( bhash )
64+
bhash, err := hex.DecodeString(hash)
65+
uhash, err := Uint256ParseFromBytes(bhash)
6766
if err != nil {
68-
fmt.Printf( "bhash len: %d\n", len(bhash) )
69-
fmt.Printf( "Uint256ParseFromBytes err: %s\n", err )
67+
fmt.Printf("bhash len: %d\n", len(bhash))
68+
fmt.Printf("Uint256ParseFromBytes err: %s\n", err)
7069
}
7170

72-
block,err := ledger.DefaultLedger.Store.GetBlock(uhash)
71+
block, err := ledger.DefaultLedger.Store.GetBlock(uhash)
7372
if err == nil {
74-
fmt.Printf( "hash: %s\n", hash )
75-
fmt.Printf( "height: %d\n", block.Blockdata.Height )
76-
fmt.Printf( "Tx Len: %d\n", len(block.Transcations) )
73+
fmt.Printf("hash: %s\n", hash)
74+
fmt.Printf("height: %d\n", block.Blockdata.Height)
75+
fmt.Printf("Tx Len: %d\n", len(block.Transcations))
7776

78-
for k:=0; k<len(block.Transcations); k++ {
77+
for k := 0; k < len(block.Transcations); k++ {
7978
txhash := block.Transcations[k].Hash()
80-
fmt.Printf( "Tx hash: %x\n", txhash.ToArray() )
81-
fmt.Printf( "Tx Type: %x\n", block.Transcations[k].TxType )
82-
fmt.Printf( "\n" )
79+
fmt.Printf("Tx hash: %x\n", txhash.ToArray())
80+
fmt.Printf("Tx Type: %x\n", block.Transcations[k].TxType)
81+
fmt.Printf("\n")
8382
}
8483
} else {
85-
fmt.Printf( "err: %s\n", err )
84+
fmt.Printf("err: %s\n", err)
8685
}
8786
}
8887

8988
func GetTx(txid string) {
90-
bhash,err := hex.DecodeString(txid)
91-
uhash,err := Uint256ParseFromBytes( bhash )
89+
bhash, err := hex.DecodeString(txid)
90+
uhash, err := Uint256ParseFromBytes(bhash)
9291
if err != nil {
93-
fmt.Printf( "bhash len: %d\n", len(bhash) )
94-
fmt.Printf( "Uint256ParseFromBytes err: %s\n", err )
92+
fmt.Printf("bhash len: %d\n", len(bhash))
93+
fmt.Printf("Uint256ParseFromBytes err: %s\n", err)
9594
}
9695

97-
tx,err := ledger.DefaultLedger.Store.GetTransaction(uhash)
96+
tx, err := ledger.DefaultLedger.Store.GetTransaction(uhash)
9897
if err == nil {
99-
fmt.Printf( "txid: %s\n", txid )
100-
fmt.Printf( "tx.TxType: %x\n", tx.TxType )
98+
fmt.Printf("txid: %s\n", txid)
99+
fmt.Printf("tx.TxType: %x\n", tx.TxType)
101100
} else {
102-
fmt.Printf( "err: %s\n", err )
101+
fmt.Printf("err: %s\n", err)
103102
}
104103
}
105104

106-
107105
func GetAsset(assetid string) {
108-
bhash,err := hex.DecodeString(assetid)
109-
uhash,err := Uint256ParseFromBytes( bhash )
106+
bhash, err := hex.DecodeString(assetid)
107+
uhash, err := Uint256ParseFromBytes(bhash)
110108
if err != nil {
111-
fmt.Printf( "bhash len: %d\n", len(bhash) )
112-
fmt.Printf( "Uint256ParseFromBytes err: %s\n", err )
109+
fmt.Printf("bhash len: %d\n", len(bhash))
110+
fmt.Printf("Uint256ParseFromBytes err: %s\n", err)
113111
}
114112

115-
asset,err := ledger.DefaultLedger.Store.GetAsset(uhash)
113+
asset, err := ledger.DefaultLedger.Store.GetAsset(uhash)
116114
if err == nil {
117-
fmt.Printf( "txid: %s\n", assetid )
115+
fmt.Printf("txid: %s\n", assetid)
118116
asset.ID
119-
fmt.Printf( "asset.TxType: %x\n", asset.AssetType )
120-
fmt.Printf( "asset.Name: %s\n", asset.Name )
121-
fmt.Printf( "asset.RecordType: %x\n", asset.RecordType )
122-
fmt.Printf( "asset.Precision: %x\n", asset.Precision )
117+
fmt.Printf("asset.TxType: %x\n", asset.AssetType)
118+
fmt.Printf("asset.Name: %s\n", asset.Name)
119+
fmt.Printf("asset.RecordType: %x\n", asset.RecordType)
120+
fmt.Printf("asset.Precision: %x\n", asset.Precision)
123121
} else {
124-
fmt.Printf( "err: %s\n", err )
122+
fmt.Printf("err: %s\n", err)
125123
}
126124
}
127125

@@ -134,7 +132,7 @@ func main() {
134132
ledger.DefaultLedger.Store.InitLedgerStore(ledger.DefaultLedger)
135133

136134
args := os.Args
137-
if args == nil || len(args)<2{
135+
if args == nil || len(args) < 2 {
138136
Usage()
139137
return
140138
}
@@ -148,7 +146,7 @@ func main() {
148146
} else if cmd == "tx" {
149147
txid := args[2]
150148
GetTx(txid)
151-
} else if cmd == "asset" {
149+
} else if cmd == "asset" {
152150
assetid := args[2]
153151
GetAsset(assetid)
154152
}

‎cli/asset/asset.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
const (
26-
RANDBYTELEN = 4
26+
RANDBYTELEN = 4
2727
REFERTXHASHLEN = 64
2828
)
2929

@@ -173,7 +173,7 @@ func makeTransferTransaction(signer *account.Account, programHashStr, assetHashS
173173
expected := transferTxOutput.Value
174174
for k, v := range unspend {
175175
h := k[0:REFERTXHASHLEN]
176-
i := k[REFERTXHASHLEN+1:]
176+
i := k[REFERTXHASHLEN + 1:]
177177
b, _ := hex.DecodeString(h)
178178
var referHash Uint256
179179
referHash.Deserialize(bytes.NewReader(b))

‎cli/common/common.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
var (
17-
Ip string
17+
Ip string
1818
Port string
1919
)
2020

‎common/Fixed64.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (f Fixed64) String() string {
4646
buffer.WriteRune('-')
4747
value = -value
4848
}
49-
buffer.WriteString(strconv.FormatInt(value/100000000, 10))
49+
buffer.WriteString(strconv.FormatInt(value / 100000000, 10))
5050
value %= 100000000
5151
if value > 0 {
5252
buffer.WriteRune('.')

‎common/common.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func ToCodeHash(code []byte) (Uint160, error) {
3030
func GetNonce() uint64 {
3131
log.Debug()
3232
// Fixme replace with the real random number generator
33-
nonce := uint64(rand.Uint32())<<32 + uint64(rand.Uint32())
33+
nonce := uint64(rand.Uint32()) << 32 + uint64(rand.Uint32())
3434
return nonce
3535
}
3636

@@ -73,7 +73,7 @@ func HexToBytes(value string) ([]byte, error) {
7373
}
7474

7575
func BytesReverse(u []byte) []byte {
76-
for i, j := 0, len(u)-1; i < j; i, j = i+1, j-1 {
76+
for i, j := 0, len(u) - 1; i < j; i, j = i + 1, j - 1 {
7777
u[i], u[j] = u[j], u[i]
7878
}
7979
return u
@@ -107,23 +107,23 @@ func GetUint16Array(source []byte) ([]uint16, error) {
107107
return nil, NewDetailErr(errors.New("[Common] , GetUint16Array err, source = nil"), ErrNoCode, "")
108108
}
109109

110-
if len(source)%2 != 0 {
110+
if len(source) % 2 != 0 {
111111
return nil, NewDetailErr(errors.New("[Common] , GetUint16Array err, length of source is odd."), ErrNoCode, "")
112112
}
113113

114-
dst := make([]uint16, len(source)/2)
115-
for i := 0; i < len(source)/2; i++ {
116-
dst[i] = uint16(source[i*2]) + uint16(source[i*2+1])*256
114+
dst := make([]uint16, len(source) / 2)
115+
for i := 0; i < len(source) / 2; i++ {
116+
dst[i] = uint16(source[i * 2]) + uint16(source[i * 2 + 1]) * 256
117117
}
118118

119119
return dst, nil
120120
}
121121

122122
func ToByteArray(source []uint16) []byte {
123-
dst := make([]byte, len(source)*2)
123+
dst := make([]byte, len(source) * 2)
124124
for i := 0; i < len(source); i++ {
125-
dst[i*2] = byte(source[i] % 256)
126-
dst[i*2+1] = byte(source[i] / 256)
125+
dst[i * 2] = byte(source[i] % 256)
126+
dst[i * 2 + 1] = byte(source[i] / 256)
127127
}
128128

129129
return dst
@@ -132,7 +132,7 @@ func ToByteArray(source []uint16) []byte {
132132
func SliceRemove(slice []uint32, h uint32) []uint32 {
133133
for i, v := range slice {
134134
if v == h {
135-
return append(slice[:i], slice[i+1:]...)
135+
return append(slice[:i], slice[i + 1:]...)
136136
}
137137
}
138138
return slice

‎common/config/config.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
const (
1212
DefaultConfigFilename = "./config.json"
13-
MINGENBLOCKTIME = 2
14-
DEFAULTGENBLOCKTIME = 6
13+
MINGENBLOCKTIME = 2
14+
DEFAULTGENBLOCKTIME = 6
1515
)
1616

1717
var Version string

‎common/inventory.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ type InventoryType byte
44

55
const (
66
TRANSACTION InventoryType = 0x01
7-
BLOCK InventoryType = 0x02
8-
CONSENSUS InventoryType = 0xe0
7+
BLOCK InventoryType = 0x02
8+
CONSENSUS InventoryType = 0xe0
99
)
1010

1111
//TODO: temp inventory

0 commit comments

Comments
 (0)