OSDN Git Service

zhen xiang
authorHAOYUatHZ <haoyu@protonmail.com>
Sun, 16 Jun 2019 02:10:42 +0000 (10:10 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sun, 16 Jun 2019 02:10:42 +0000 (10:10 +0800)
federation/service/node.go
federation/warder.go

index fab5e79..4dc0af0 100644 (file)
@@ -73,22 +73,26 @@ type submitTxResp struct {
        TxID string `json:"tx_id"`
 }
 
-func (n *Node) SubmitMainchainTx(tx *btmTypes.Tx) (string, error) {
+func (n *Node) SubmitTx(tx interface{} /*, isMainchain bool*/) (string, error) {
        url := "/submit-transaction"
-       payload, err := json.Marshal(submitMainchainTxReq{Tx: tx})
-       if err != nil {
-               return "", errors.Wrap(err, "json marshal")
-       }
-
-       res := &submitTxResp{}
-       return res.TxID, n.request(url, payload, res)
-}
-
-func (n *Node) SubmitSidechainTx(tx *vaporTypes.Tx) (string, error) {
-       url := "/submit-transaction"
-       payload, err := json.Marshal(submitSidechainTxReq{Tx: tx})
-       if err != nil {
-               return "", errors.Wrap(err, "json marshal")
+       var payload []byte
+       var err error
+
+       switch tx := tx.(type) {
+       case *btmTypes.Tx:
+               payload, err = json.Marshal(submitMainchainTxReq{Tx: tx})
+               if err != nil {
+                       return "", errors.Wrap(err, "json marshal")
+               }
+
+       case *vaporTypes.Tx:
+               payload, err = json.Marshal(submitSidechainTxReq{Tx: tx})
+               if err != nil {
+                       return "", errors.Wrap(err, "json marshal")
+               }
+
+       default:
+               return "", errors.New("unknown tx type")
        }
 
        res := &submitTxResp{}
index 09609dd..4ef9718 100644 (file)
@@ -198,10 +198,10 @@ func (w *warder) isLeader() bool {
 func (w *warder) submitTx(destTx interface{}) (string, error) {
        switch tx := destTx.(type) {
        case *btmTypes.Tx:
-               return w.mainchainNode.SubmitMainchainTx(tx)
+               return w.mainchainNode.SubmitTx(tx /*, true*/)
 
        case *vaporTypes.Tx:
-               return w.sidechainNode.SubmitSidechainTx(tx)
+               return w.sidechainNode.SubmitTx(tx /*, false*/)
 
        default:
                return "", errors.New("unknown destTx type")