Skip to content

Commit

Permalink
Merge branch 'anylock' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Jun 3, 2024
2 parents 1deba62 + 304f3aa commit 373eedd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
3 changes: 1 addition & 2 deletions http_server/handle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/dotbitHQ/das-lib/common"
"github.com/dotbitHQ/das-lib/txbuilder"
"github.com/nervosnetwork/ckb-sdk-go/types"
"github.com/scorpiotzh/toolib"
"github.com/shopspring/decimal"
"time"
Expand Down Expand Up @@ -39,7 +38,7 @@ type SignInfo struct {
SignAddress string `json:"sign_address,omitempty"` // sign address
SignList []txbuilder.SignData `json:"sign_list"` // sign list
MMJson *common.MMJsonObj `json:"mm_json"` // 712 mmjson
CKBTx *types.Transaction `json:"ckb_tx"`
CKBTx string `json:"ckb_tx"`
}

func (s *SignInfo) SignListString() string {
Expand Down
23 changes: 12 additions & 11 deletions http_server/handle/reverse_declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ func (h *HttpHandle) checkTxFee(txBuilder *txbuilder.DasTxBuilder, txParams *txb
return txBuilder, nil
}

func (h *HttpHandle) buildTx(req *reqBuildTx, txParams *txbuilder.BuildTransactionParams) (*types.Transaction, *SignInfo, error) {
func (h *HttpHandle) buildTx(req *reqBuildTx, txParams *txbuilder.BuildTransactionParams) (string, *SignInfo, error) {
rebuildTxParams, err := txbuilder.DeepCopyTxParams(txParams)
if err != nil {
return nil, nil, fmt.Errorf("deepCopy err %s", err.Error())
return "", nil, fmt.Errorf("deepCopy err %s", err.Error())
}
txBuilder := txbuilder.NewDasTxBuilderFromBase(h.txBuilderBase, nil)
if err := txBuilder.BuildTransaction(txParams); err != nil {
return nil, nil, fmt.Errorf("txBuilder.BuildTransaction err: %s", err.Error())
return "", nil, fmt.Errorf("txBuilder.BuildTransaction err: %s", err.Error())
}
sizeInBlock, _ := txBuilder.Transaction.SizeInBlock()
txFeeRate := config.Cfg.Server.TxTeeRate
Expand Down Expand Up @@ -336,13 +336,13 @@ func (h *HttpHandle) buildTx(req *reqBuildTx, txParams *txbuilder.BuildTransacti
case common.DasActionBidExpiredAccountAuction:
accTx, err := h.dasCore.Client().GetTransaction(h.ctx, txParams.Inputs[0].PreviousOutput.TxHash)
if err != nil {
return nil, nil, fmt.Errorf("GetTransaction err: %s", err.Error())
return "", nil, fmt.Errorf("GetTransaction err: %s", err.Error())
}
accLock := accTx.Transaction.Outputs[txParams.Inputs[0].PreviousOutput.Index].Lock

dpTx, err := h.dasCore.Client().GetTransaction(h.ctx, txParams.Inputs[1].PreviousOutput.TxHash)
if err != nil {
return nil, nil, fmt.Errorf("GetTransaction err: %s", err.Error())
return "", nil, fmt.Errorf("GetTransaction err: %s", err.Error())
}
dpLock := dpTx.Transaction.Outputs[txParams.Inputs[1].PreviousOutput.Index].Lock
if !accLock.Equals(dpLock) {
Expand All @@ -364,24 +364,25 @@ func (h *HttpHandle) buildTx(req *reqBuildTx, txParams *txbuilder.BuildTransacti
//}
newTxBuilder, err := txbuilder.CheckTxFee(checkTxFeeParam)
if err != nil {
return nil, nil, fmt.Errorf("CheckTxFee err %s ", err.Error())
return "", nil, fmt.Errorf("CheckTxFee err %s ", err.Error())
}
if newTxBuilder != nil {
txBuilder = newTxBuilder
}
signList, err := txBuilder.GenerateDigestListFromTx(skipGroups)
if err != nil {
return nil, nil, fmt.Errorf("txBuilder.GenerateDigestListFromTx err: %s", err.Error())
return "", nil, fmt.Errorf("txBuilder.GenerateDigestListFromTx err: %s", err.Error())
}

log.Info("buildTx:", txBuilder.TxString())
txStr := txBuilder.TxString()
log.Info("buildTx:", txStr)

var mmJsonObj *common.MMJsonObj
for _, v := range signList {
if v.SignType == common.DasAlgorithmIdEth712 && v.SignMsg != "" {
mmJsonObj, err = txBuilder.BuildMMJsonObj(req.EvmChainId)
if req.Action != tables.DasActionTransferBalance && err != nil {
return nil, nil, fmt.Errorf("txBuilder.BuildMMJsonObj err: %s", err.Error())
return "", nil, fmt.Errorf("txBuilder.BuildMMJsonObj err: %s", err.Error())
} else {
log.Info("BuildTx:", mmJsonObj.String())
}
Expand All @@ -406,7 +407,7 @@ func (h *HttpHandle) buildTx(req *reqBuildTx, txParams *txbuilder.BuildTransacti
signKey := sic.SignKey()
cacheStr := toolib.JsonString(&sic)
if err = h.rc.SetSignTxCache(signKey, cacheStr); err != nil {
return nil, nil, fmt.Errorf("SetSignTxCache err: %s", err.Error())
return "", nil, fmt.Errorf("SetSignTxCache err: %s", err.Error())
}

var si SignInfo
Expand All @@ -416,7 +417,7 @@ func (h *HttpHandle) buildTx(req *reqBuildTx, txParams *txbuilder.BuildTransacti

//tx := txbuilder.TxToTransaction(txBuilder.Transaction)

return txBuilder.Transaction, &si, nil
return txStr, &si, nil
}

func doBuildTxErr(err error, apiResp *api_code.ApiResp) {
Expand Down
9 changes: 7 additions & 2 deletions http_server/handle/transaction_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/dotbitHQ/das-lib/witness"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
"github.com/nervosnetwork/ckb-sdk-go/rpc"
"github.com/scorpiotzh/toolib"
"net/http"
"strings"
Expand Down Expand Up @@ -135,13 +136,17 @@ func (h *HttpHandle) doTransactionSend(req *ReqTransactionSend, apiResp *api_cod
}

// sign
if req.CKBTx != nil && len(req.CKBTx.Inputs) > 0 {
if req.CKBTx != "" {
userTx, err := rpc.TransactionFromString(req.CKBTx)
if err != nil {
apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("rpc.TransactionFromString err: %s", err.Error()))
return fmt.Errorf("rpc.TransactionFromString err: %s", err.Error())
}
cacheTxHash, err := sic.BuilderTx.Transaction.ComputeHash()
if err != nil {
apiResp.ApiRespErr(api_code.ApiCodeError500, "ComputeHash err")
return fmt.Errorf("ComputeHash err: %s", err.Error())
}
userTx := req.CKBTx
//userTx := txbuilder.TransactionToTx(req.CKBTx)
userTxHash, err := userTx.ComputeHash()
if err != nil {
Expand Down

0 comments on commit 373eedd

Please sign in to comment.