Skip to content

Commit

Permalink
feat(model): add service fee to onchain BTC transactions (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmquang authored Feb 26, 2025
1 parent 92c773d commit 84eaf4f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions internal/model/onchain_btc_processed_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ type OnchainBtcProcessedTransaction struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
NetworkFee string `gorm:"column:network_fee" json:"network_fee"`
ServiceFee string `gorm:"column:service_fee" json:"service_fee"`
TotalAmount string `gorm:"-" json:"total_amount"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func (s *store) Find(db *gorm.DB, filter ListFilter) ([]*model.OnchainBtcProcess
if err != nil {
continue
}
networkFee, err := strconv.ParseInt(transactions[i].NetworkFee, 10, 64)
svcFee, err := strconv.ParseInt(transactions[i].ServiceFee, 10, 64)
if err != nil {
continue
}
totalAmount := amount - networkFee
totalAmount := amount - svcFee
transactions[i].TotalAmount = strconv.FormatInt(totalAmount, 10)
}

Expand Down
14 changes: 8 additions & 6 deletions internal/utils/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ type DBConnection struct {
}

type BitcoinConfig struct {
WalletWIF string
BlockstreamAPIURL string
MaxTxFeeUSD float64
WalletWIF string
BlockstreamAPIURL string
MaxTxFeeUSD float64
ServiceFeePercentage float64
}

func New() *AppConfig {
Expand All @@ -73,9 +74,10 @@ func New() *AppConfig {
SSLMode: os.Getenv("DB_SSL_MODE"),
},
Bitcoin: BitcoinConfig{
WalletWIF: os.Getenv("BTC_WALLET_WIF"),
BlockstreamAPIURL: os.Getenv("BTC_BLOCKSTREAM_API_URL"),
MaxTxFeeUSD: envVarAsFloat("BTC_MAX_TX_FEE_USD", 1.0),
WalletWIF: os.Getenv("BTC_WALLET_WIF"),
BlockstreamAPIURL: os.Getenv("BTC_BLOCKSTREAM_API_URL"),
MaxTxFeeUSD: envVarAsFloat("BTC_MAX_TX_FEE_USD", 1.0),
ServiceFeePercentage: envVarAsFloat("BTC_SERVICE_FEE_PERCENTAGE", 0.01),
},
Blockchain: BlockchainConfig{
BaseRPCEndpoint: os.Getenv("BLOCKCHAIN_BASE_RPC_ENDPOINT"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE onchain_btc_processed_transactions
DROP COLUMN IF EXISTS service_fee;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE onchain_btc_processed_transactions
ADD COLUMN service_fee VARCHAR(255) DEFAULT '0';

0 comments on commit 84eaf4f

Please sign in to comment.