FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use proto.DatabaseID instead of *proto.DatabaseID · developgo/CovenantSQL@324ee20 · GitHub

Commit 324ee20

Browse files
Qi Xiao
committed
Use proto.DatabaseID instead of *proto.DatabaseID
1 parent 607bcf5 commit 324ee20

12 files changed

Lines changed: 31 additions & 33 deletions

File tree

‎blockproducer/metastate.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error)
719719
AdvancePayment: tx.AdvancePayment,
720720
}
721721
// generate genesis block
722-
gb, err := s.generateGenesisBlock(*dbID, tx.ResourceMeta)
722+
gb, err := s.generateGenesisBlock(dbID, tx.ResourceMeta)
723723
if err != nil {
724724
log.WithFields(log.Fields{
725725
"dbID": dbID,
@@ -739,7 +739,7 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error)
739739

740740
// create sqlchain
741741
sp := &types.SQLChainProfile{
742-
ID: *dbID,
742+
ID: dbID,
743743
Address: dbAddr,
744744
Period: sqlchainPeriod,
745745
GasPrice: tx.GasPrice,
@@ -750,16 +750,16 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error)
750750
Miners: miners[:],
751751
}
752752

753-
if _, loaded := s.loadSQLChainObject(*dbID); loaded {
754-
err = errors.Wrapf(ErrDatabaseExists, "database exists: %s", string(*dbID))
753+
if _, loaded := s.loadSQLChainObject(dbID); loaded {
754+
err = errors.Wrapf(ErrDatabaseExists, "database exists: %s", dbID)
755755
return
756756
}
757757
s.dirty.accounts[dbAddr] = &types.Account{Address: dbAddr}
758-
s.dirty.databases[*dbID] = sp
758+
s.dirty.databases[dbID] = sp
759759
for _, miner := range tx.ResourceMeta.TargetMiners {
760760
s.deleteProviderObject(miner)
761761
}
762-
log.Infof("success create sqlchain with database ID: %s", string(*dbID))
762+
log.Infof("success create sqlchain with database ID: %s", dbID)
763763
return
764764
}
765765

‎blockproducer/metastate_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ func TestMetaState(t *testing.T) {
897897
uint64(conf.GConf.UpdatePeriod) * uint64(len(cd2.ResourceMeta.TargetMiners))
898898
So(b1-b2, ShouldEqual, cd1.AdvancePayment+minAdvancePayment)
899899
dbID := proto.FromAccountAndNonce(cd1.Owner, uint32(cd1.Nonce))
900-
co, loaded = ms.loadSQLChainObject(*dbID)
900+
co, loaded = ms.loadSQLChainObject(dbID)
901901
So(loaded, ShouldBeTrue)
902902
dbAccount, err := dbID.AccountAddress()
903903
So(err, ShouldBeNil)
@@ -961,7 +961,7 @@ func TestMetaState(t *testing.T) {
961961
err = ms.apply(&up)
962962
So(errors.Cause(err), ShouldEqual, ErrAccountPermissionDeny)
963963

964-
co, loaded = ms.loadSQLChainObject(*dbID)
964+
co, loaded = ms.loadSQLChainObject(dbID)
965965
for _, user := range co.Users {
966966
if user.Address == addr1 {
967967
So(user.Permission, ShouldEqual, types.Read)
@@ -1032,7 +1032,7 @@ func TestMetaState(t *testing.T) {
10321032
So(err, ShouldBeNil)
10331033
ms.commit()
10341034

1035-
co, loaded = ms.loadSQLChainObject(*dbID)
1035+
co, loaded = ms.loadSQLChainObject(dbID)
10361036
for _, miner := range co.Miners {
10371037
if miner.Address == addr1 {
10381038
So(miner.EncryptionKey, ShouldEqual, encryptKey)
@@ -1093,7 +1093,7 @@ func TestMetaState(t *testing.T) {
10931093
So(err, ShouldBeNil)
10941094
err = ms.apply(ub2)
10951095
ms.commit()
1096-
sqlchain, loaded := ms.loadSQLChainObject(*dbID)
1096+
sqlchain, loaded := ms.loadSQLChainObject(dbID)
10971097
So(loaded, ShouldBeTrue)
10981098
So(len(sqlchain.Miners), ShouldEqual, 1)
10991099
So(sqlchain.Miners[0].PendingIncome, ShouldEqual, 125)
@@ -1140,7 +1140,7 @@ func TestMetaState(t *testing.T) {
11401140
So(err, ShouldBeNil)
11411141
err = ms.apply(ub3)
11421142
So(err, ShouldBeNil)
1143-
sqlchain, loaded = ms.loadSQLChainObject(*dbID)
1143+
sqlchain, loaded = ms.loadSQLChainObject(dbID)
11441144
So(loaded, ShouldBeTrue)
11451145
So(len(sqlchain.Miners), ShouldEqual, 1)
11461146
So(sqlchain.Miners[0].PendingIncome, ShouldEqual, 115)

‎blockproducer/rpc.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func Create(
225225
return
226226
}
227227

228-
dbID = *proto.FromAccountAndNonce(clientAddr, uint32(nonceResp.Nonce))
228+
dbID = proto.FromAccountAndNonce(clientAddr, uint32(nonceResp.Nonce))
229229
dsn = fmt.Sprintf("cql://%s", string(dbID))
230230
return
231231
}

‎client/driver.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func Create(meta ResourceMeta) (dsn string, err error) {
181181
}
182182

183183
cfg := NewConfig()
184-
cfg.DatabaseID = string(*proto.FromAccountAndNonce(clientAddr, uint32(nonceResp.Nonce)))
184+
cfg.DatabaseID = string(proto.FromAccountAndNonce(clientAddr, uint32(nonceResp.Nonce)))
185185
dsn = cfg.FormatDSN()
186186

187187
return

‎client/driver_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestCreate(t *testing.T) {
7373
var addr proto.AccountAddress
7474
addr, err = crypto.PubKeyHash(priv.PubKey())
7575
So(err, ShouldBeNil)
76-
var dbid = string(*proto.FromAccountAndNonce(addr, uint32(stubNextNonce)))
76+
var dbid = string(proto.FromAccountAndNonce(addr, uint32(stubNextNonce)))
7777

7878
recoveredCfg, err := ParseDSN(dsn)
7979
So(err, ShouldBeNil)

‎proto/proto.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ func (d *DatabaseID) AccountAddress() (a AccountAddress, err error) {
176176
}
177177

178178
// FromAccountAndNonce generates databaseID from Account and its nonce.
179-
func FromAccountAndNonce(accountAddress AccountAddress, nonce uint32) *DatabaseID {
179+
func FromAccountAndNonce(accountAddress AccountAddress, nonce uint32) DatabaseID {
180180
addrAndNonce := fmt.Sprintf("%s%d", accountAddress.String(), nonce)
181181
rawID := hash.THashH([]byte(addrAndNonce))
182-
d := DatabaseID(rawID.String())
183-
return &d
182+
return DatabaseID(rawID.String())
184183
}

‎proto/proto_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestFromAccountAndNonce(t *testing.T) {
100100
So(err, ShouldBeNil)
101101
a := AccountAddress(*h)
102102
dbID := FromAccountAndNonce(a, target[i].nonce)
103-
So(string(*dbID), ShouldResemble, target[i].result)
103+
So(string(dbID), ShouldResemble, target[i].result)
104104
}
105105
})
106106
}

‎types/billing.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func (tb *Billing) GetAccountNonce() pi.AccountNonce {
8989
}
9090

9191
// GetDatabaseID gets the database ID.
92-
func (tb *Billing) GetDatabaseID() *proto.DatabaseID {
93-
return &tb.BillingRequest.Header.DatabaseID
92+
func (tb *Billing) GetDatabaseID() proto.DatabaseID {
93+
return tb.BillingRequest.Header.DatabaseID
9494
}
9595

9696
func init() {

‎types/billing_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func TestBilling_PackAndSignTx(t *testing.T) {
129129

130130
tb.GetAccountNonce()
131131

132-
if tb.GetDatabaseID() == nil {
133-
t.Fatal("get nil DatabaseID")
132+
if len(tb.GetDatabaseID()) == 0 {
133+
t.Fatal("get empty DatabaseID")
134134
}
135135

136136
tb.Signature = nil

‎types/xxx_test.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func generateRandomAccountAddresses(n int) (s []proto.AccountAddress) {
7373

7474
func generateRandomProfile() *SQLChainProfile {
7575
return &SQLChainProfile{
76-
ID: *generateRandomDatabaseID(),
76+
ID: generateRandomDatabaseID(),
7777
Owner: proto.AccountAddress(generateRandomHash()),
7878
Users: generateRandomSQLChainUsers(rand.Intn(10) + 1),
7979
}
@@ -106,9 +106,8 @@ func generateRandomHash() hash.Hash {
106106

107107
}
108108

109-
func generateRandomDatabaseID() *proto.DatabaseID {
110-
id := proto.DatabaseID(randStringBytes(uuidLen))
111-
return &id
109+
func generateRandomDatabaseID() proto.DatabaseID {
110+
return proto.DatabaseID(randStringBytes(uuidLen))
112111

113112
}
114113

@@ -172,7 +171,7 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *BPBlock, err erro
172171

173172
func generateRandomBillingRequestHeader() *BillingRequestHeader {
174173
return &BillingRequestHeader{
175-
DatabaseID: *generateRandomDatabaseID(),
174+
DatabaseID: generateRandomDatabaseID(),
176175
LowBlock: generateRandomHash(),
177176
LowHeight: rand.Int31(),
178177
HighBlock: generateRandomHash(),

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL