Skip to content

Commit

Permalink
Merge branch 'feat/dogecoin'
Browse files Browse the repository at this point in the history
# Conflicts:
#	tables/t_das_order_info.go
#	timer/hedge.go
  • Loading branch information
scorpiotzh committed Mar 21, 2023
2 parents 8634952 + 36edb0b commit b0403ec
Show file tree
Hide file tree
Showing 16 changed files with 684 additions and 23 deletions.
4 changes: 4 additions & 0 deletions chain/chain_sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const (
SignMethodCkb string = "wallet_cKBSignMsg"
)

func (r *RemoteSignClient) Client() rpc.Client {
return r.client
}

func (r *RemoteSignClient) SignCkbMessage(ckbSignerAddress, message string) ([]byte, error) {
if common.Has0xPrefix(message) {
message = message[2:]
Expand Down
3 changes: 2 additions & 1 deletion cmd/refund/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ func runServer(ctx *cli.Context) error {
Ctx: ctxServer,
Wg: &wgServer,
}
dt.InitChain(kp)
if config.Cfg.Server.RemoteSignApiUrl != "" {
signClient, err := chain_sign.NewRemoteSignClient(ctxServer, config.Cfg.Server.RemoteSignApiUrl)
if err != nil {
return fmt.Errorf("chain_common.NewRemoteSignClient err: %s", err.Error())
}
dt.SignClient = signClient
}
dt.InitChain(kp)

if err := dt.DoOrderRefund(); err != nil {
return fmt.Errorf("dt.DoOrderRefund() err: %s", err.Error())
}
Expand Down
11 changes: 11 additions & 0 deletions config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ chain:
current_block_number: 0
confirm_num: 10
concurrency_num: 10
doge:
refund: true
switch: true
node_rpc: ""
user: ""
password: ""
address: ""
private: ""
current_block_number: 0
confirm_num: 10
concurrency_num: 10
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ type CfgServer struct {
Tron EvmNode `json:"tron" yaml:"tron"`
Bsc EvmNode `json:"bsc" yaml:"bsc"`
Polygon EvmNode `json:"polygon" yaml:"polygon"`
Doge struct {
Refund bool `json:"refund" yaml:"refund"`
Switch bool `json:"switch" yaml:"switch"`
NodeRpc string `json:"node_rpc" yaml:"node_rpc"`
User string `json:"user" yaml:"user"`
Password string `json:"password" yaml:"password"`
Address string `json:"address" yaml:"address"`
Private string `json:"private" yaml:"private"`
CurrentBlockNumber uint64 `json:"current_block_number" yaml:"current_block_number"`
ConfirmNum uint64 `json:"confirm_num" yaml:"confirm_num"`
ConcurrencyNum uint64 `json:"concurrency_num" yaml:"concurrency_num"`
} `json:"doge" yaml:"doge"`
} `json:"chain" yaml:"chain"`
}

Expand Down
38 changes: 33 additions & 5 deletions dao/t_das_order_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ package dao

import (
"das-pay/tables"
"github.com/dotbitHQ/das-lib/common"
"github.com/shopspring/decimal"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)

func (d *DbDao) GetOrderByOrderId(orderId string) (order tables.TableDasOrderInfo, err error) {
err = d.db.Where("order_id=? AND order_type=?", orderId, tables.OrderTypeSelf).Find(&order).Error
err = d.db.Where("order_id=? AND order_type=?",
orderId, tables.OrderTypeSelf).Find(&order).Error
return
}

func (d *DbDao) GetOrderByAddrWithPayAmount(chainType common.ChainType, addr string, payAmount decimal.Decimal) (order tables.TableDasOrderInfo, err error) {
err = d.db.Where("chain_type=? AND address=? AND pay_amount=? AND order_type=?",
chainType, addr, payAmount, tables.OrderTypeSelf).
Order("id DESC").Limit(1).Find(&order).Error
return
}

Expand All @@ -32,13 +42,22 @@ func (d *DbDao) UpdatePayStatus(payInfo *tables.TableDasOrderPayInfo) error {
return err
}

if err := tx.Clauses(clause.OnConflict{
DoUpdates: clause.AssignmentColumns([]string{
"chain_type", "address", "status", "account_id",
}),
if err := tx.Clauses(clause.Insert{
Modifier: "IGNORE",
}).Create(&payInfo).Error; err != nil {
return err
}

if err := tx.Model(tables.TableDasOrderPayInfo{}).
Where("`hash`=? AND order_id=?", payInfo.Hash, payInfo.OrderId).
Updates(map[string]interface{}{
"chain_type": payInfo.ChainType,
"address": payInfo.Address,
"status": payInfo.Status,
"account_id": payInfo.AccountId,
}).Error; err != nil {
return err
}
return nil
})
}
Expand All @@ -56,3 +75,12 @@ func (d *DbDao) UpdateHedgeStatus(orderId string, oldStatus, newStatus tables.Tx
"hedge_status": newStatus,
}).Error
}

func (d *DbDao) GetOrders(orderIds []string) (list []tables.TableDasOrderInfo, err error) {
if len(orderIds) == 0 {
return
}
err = d.db.Select("order_id,action,pay_status,register_status,order_status").
Where("order_id IN(?)", orderIds).Find(&list).Error
return
}
7 changes: 6 additions & 1 deletion dao/t_das_order_pay_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d *DbDao) CreateOrderPays(list []tables.TableDasOrderPayInfo) error {

func (d *DbDao) UpdateRefundStatus(hashList []string, oldStatus, newStatus tables.TxStatus) error {
return d.db.Model(tables.TableDasOrderPayInfo{}).
Where("hash IN(?) AND refund_status=?", hashList, oldStatus).
Where("hash IN(?) AND status=? AND refund_status=?", hashList, tables.OrderTxStatusConfirm, oldStatus).
Updates(map[string]interface{}{
"refund_status": newStatus,
}).Error
Expand All @@ -59,3 +59,8 @@ func (d *DbDao) GetUnRefundTxCount() (count int64, err error) {
Where("`status`=? AND refund_status=?", tables.OrderTxStatusConfirm, tables.TxStatusSending).Count(&count).Error
return
}

func (d *DbDao) GetPayInfoByHash(hash string) (info tables.TableDasOrderPayInfo, err error) {
err = d.db.Where("hash=?", hash).Find(&info).Error
return
}
65 changes: 65 additions & 0 deletions example/doge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package example

import (
"context"
"fmt"
"github.com/dotbitHQ/das-lib/bitcoin"
"github.com/shopspring/decimal"
"testing"
)

func getRpcClient() *bitcoin.BaseRequest {
baseRep := bitcoin.BaseRequest{
RpcUrl: "",
User: "",
Password: "",
Proxy: "socks5://127.0.0.1:8838",
}
return &baseRep
}

func TestDogeTx(t *testing.T) {
rpcClient := getRpcClient()
txTool := bitcoin.TxTool{
RpcClient: rpcClient,
Ctx: context.Background(),
RemoteSignClient: nil,
DustLimit: bitcoin.DustLimitDoge,
Params: bitcoin.GetDogeMainNetParams(),
}

// get utxo
addr := "DP86MSmWjEZw8GKotxcvAaW5D4e3qoEh6f"
privateKey := ""
payAmount := int64(102153551)
_, uos, err := txTool.GetUnspentOutputsDoge(addr, privateKey, payAmount)
if err != nil {
t.Fatal(err)
}

// transfer
tx, err := txTool.NewTx(uos, []string{addr}, []int64{payAmount}, "")
if err != nil {
t.Fatal(err)
}

_, err = txTool.LocalSignTx(tx, uos)
if err != nil {
t.Fatal(err)
}

hash, err := txTool.SendTx(tx)
if err != nil {
t.Fatal(err)
}
fmt.Println("hash:", hash)
}

func TestValue(t *testing.T) {
//fmt.Println(decimal.NewFromInt(133333333).DivRound(decimal.NewFromInt(1e8), 8))
//fmt.Println(decimal.NewFromFloat(float64(1.33333333) * 1e8).String())
//fmt.Println(decimal.NewFromFloat(float64(1.33333333) * 1e8).Cmp(decimal.NewFromInt(133333333)))
decValue := decimal.NewFromFloat(1.33333333)
decValue = decValue.Mul(decimal.NewFromInt(1e8))
fmt.Println(decValue.String())
}
13 changes: 10 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@ module das-pay
go 1.16

require (
github.com/dotbitHQ/das-lib v1.0.1-0.20221031074915-2a8a6bbb7d16
github.com/elazarl/goproxy v0.0.0-20220529153421-8ea89ba92021 // indirect
github.com/btcsuite/btcd v0.23.0
github.com/dotbitHQ/das-lib v1.0.1-0.20230321033933-9c3f96663bbe
github.com/ethereum/go-ethereum v1.10.17
github.com/fbsobreira/gotron-sdk v0.0.0-20211102183839-58a64f4da5f4
github.com/fsnotify/fsnotify v1.5.4
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.7 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/nervosnetwork/ckb-sdk-go v0.101.3
github.com/parnurzeal/gorequest v0.2.16
github.com/robfig/cron/v3 v3.0.1
github.com/scorpiotzh/mylog v1.0.10
github.com/scorpiotzh/toolib v1.1.3
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.7.1 // indirect
github.com/urfave/cli/v2 v2.5.0
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
google.golang.org/grpc v1.46.0
gorm.io/gorm v1.22.1
moul.io/http2curl v1.0.0 // indirect
)

replace (
Expand Down
Loading

0 comments on commit b0403ec

Please sign in to comment.