Skip to content

Commit

Permalink
fix (#261)
Browse files Browse the repository at this point in the history
Signed-off-by: ReyisaRuby <yisa@reddio.com>
  • Loading branch information
ReyisaRuby authored Jan 8, 2025
1 parent 883f798 commit 7335c0e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/txdb/txdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func (t *txnkvdb) SetTxns(txns []*SignedTxn) (err error) {
}

type TxnDBSchema struct {
Type string `gorm:"type:varchar(10)"`
Key string `gorm:"primaryKey;type:text"`
Value string `gorm:"type:text"`
Type string `gorm:"type:varchar(10)"`
HashKey string `gorm:"primaryKey,length:255;type:text"`
Value []byte `gorm:"type:blob"`
}

func (TxnDBSchema) TableName() string {
Expand Down Expand Up @@ -126,10 +126,10 @@ func (bb *TxDB) GetTxn(txnHash Hash) (stxn *SignedTxn, err error) {
}
if bb.enableUseSql {
var records []TxnDBSchema
err := bb.db.Db().Raw("select value from txndb where type = ? and key = ?", "txn", txnHash.String()).Find(&records).Error
err := bb.db.Db().Raw("select value from txndb where type = ? and hash_key = ?", "txn", txnHash.String()).Find(&records).Error
// find result in sql database
if err == nil && len(records) > 0 {
return DecodeSignedTxn([]byte(records[0].Value))
return DecodeSignedTxn(records[0].Value)
}
}
return bb.txnKV.GetTxn(txnHash)
Expand Down Expand Up @@ -162,7 +162,7 @@ func (bb *TxDB) ExistTxn(txnHash Hash) bool {
}
if bb.enableUseSql {
var records []TxnDBSchema
err := bb.db.Db().Raw("select value from txndb where type = ? and key = ?", "txn", txnHash.String()).Find(&records).Error
err := bb.db.Db().Raw("select value from txndb where type = ? and hash_key = ?", "txn", txnHash.String()).Find(&records).Error
if err == nil && len(records) > 0 {
return true
}
Expand All @@ -184,7 +184,7 @@ func (bb *TxDB) SetTxns(txns []*SignedTxn) (err error) {
logrus.Errorf("TxDB.SetTxns set tx(%s) failed: %v", txn.TxnHash.String(), err)
return err
}
if err := bb.db.Db().Exec("insert into txndb (type,key,value) values (?,?,?)", "txn", txn.TxnHash.String(), string(txbyt)).Error; err != nil {
if err := bb.db.Db().Exec("insert into txndb (type, hash_key, value) values (?,?,?)", "txn", txn.TxnHash.String(), txbyt).Error; err != nil {
logrus.Errorf("Insert TxDB.SetTxns tx(%s) failed: %v", txn.TxnHash.String(), err)
return err
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (bb *TxDB) SetReceipt(txHash Hash, receipt *Receipt) (err error) {
if err != nil {
return err
}
if err := bb.db.Db().Exec("insert into txndb (type,key,value) values (?,?,?)", "receipt", txHash.String(), string(byt)).Error; err != nil {
if err := bb.db.Db().Exec("insert into txndb (type, hash_key, value) values (?,?,?)", "receipt", txHash.String(), byt).Error; err != nil {
return err
}
return nil
Expand All @@ -232,10 +232,10 @@ func (bb *TxDB) GetReceipt(txHash Hash) (rec *Receipt, err error) {
}()
if bb.enableUseSql {
var records []TxnDBSchema
err := bb.db.Db().Raw("select value from txndb where type = ? and key = ?", "receipt", txHash.String()).Find(&records).Error
err := bb.db.Db().Raw("select value from txndb where type = ? and hash_key = ?", "receipt", txHash.String()).Find(&records).Error
if err == nil && len(records) > 0 {
receipt := new(Receipt)
err = receipt.Decode([]byte(records[0].Value))
err = receipt.Decode(records[0].Value)
if err == nil {
return receipt, nil
}
Expand Down

0 comments on commit 7335c0e

Please sign in to comment.