Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//nolint:dupl,unparam
package main

import (
"encoding/binary"
"encoding/json"
"fmt"
"github.com/meshplus/bitxhub-core/agency"
"os"
"strconv"
"strings"
"time"

"github.com/meshplus/bitxhub-core/agency"

"github.com/Rican7/retry"
"github.com/Rican7/retry/strategy"
"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -129,10 +131,7 @@ func (c *Client) Initialize(configPath string, extra []byte, mode string) error
// m = make(map[string]*pb.Interchain)
// }

mgh, err := newFabricHandler(contractmeta.EventFilter, eventC)
if err != nil {
return err
}
mgh := newFabricHandler(contractmeta.EventFilter, eventC)

done := make(chan bool)
csm, err := NewConsumer(configPath, contractmeta, mgh, done)
Expand Down Expand Up @@ -316,6 +315,7 @@ func (c *Client) getProof(response channel.Response) ([]byte, error) {
return nil
}, strategy.Wait(2*time.Second)); err != nil {
logger.Error("Can't get proof", "error", err.Error())
return nil, err
}

return proof, nil
Expand Down Expand Up @@ -400,6 +400,9 @@ func (c *Client) SubmitIBTP(from string, index uint64, serviceID string, ibtpTyp
destFullID := c.bitxhubID + ":" + c.appchainID + ":" + serviceID
servicePair := from + "-" + destFullID
ibtp, err := c.GetReceiptMessage(servicePair, index)
if err != nil {
return nil, err
}
ret.Result = ibtp

return ret, nil
Expand Down Expand Up @@ -891,11 +894,11 @@ type handler struct {
ID string
}

func newFabricHandler(eventFilter string, eventC chan *pb.IBTP) (*handler, error) {
func newFabricHandler(eventFilter string, eventC chan *pb.IBTP) *handler {
return &handler{
eventC: eventC,
eventFilter: eventFilter,
}, nil
}
}

func (h *handler) HandleMessage(deliveries *fab.CCEvent, payload []byte) {
Expand All @@ -910,14 +913,14 @@ func (h *handler) HandleMessage(deliveries *fab.CCEvent, payload []byte) {
}
}

func parseChainServiceID(id string) (string, string, string, error) {
splits := strings.Split(id, ":")
if len(splits) != 3 {
return "", "", "", fmt.Errorf("invalid chain service ID: %s", id)
}
// func parseChainServiceID(id string) (string, string, string, error) {
// splits := strings.Split(id, ":")
// if len(splits) != 3 {
// return "", "", "", fmt.Errorf("invalid chain service ID: %s", id)
// }

return splits[0], splits[1], splits[2], nil
}
// return splits[0], splits[1], splits[2], nil
// }

func parseServicePair(servicePair string) (string, string, error) {
splits := strings.Split(servicePair, "-")
Expand All @@ -928,9 +931,9 @@ func parseServicePair(servicePair string) (string, string, error) {
return splits[0], splits[1], nil
}

func genServicePair(from, to string) string {
return fmt.Sprintf("%s-%s", from, to)
}
// func genServicePair(from, to string) string {
// return fmt.Sprintf("%s-%s", from, to)
// }

func (c *Client) GetOffChainData(request *pb.GetDataRequest) (*pb.OffChainDataInfo, error) {
//TODO implement me
Expand Down
1 change: 1 addition & 0 deletions consumer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:unparam
package main

import (
Expand Down
18 changes: 8 additions & 10 deletions event.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"strings"

"github.com/cloudflare/cfssl/log"
"github.com/ethereum/go-ethereum/crypto"
"github.com/meshplus/bitxhub-model/pb"
Expand Down Expand Up @@ -34,14 +32,14 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB
}
}

func handleArgs(args string) [][]byte {
argsBytes := make([][]byte, 0)
as := strings.Split(args, ",")
for _, a := range as {
argsBytes = append(argsBytes, []byte(a))
}
return argsBytes
}
// func handleArgs(args string) [][]byte {
// argsBytes := make([][]byte, 0)
// as := strings.Split(args, ",")
// for _, a := range as {
// argsBytes = append(argsBytes, []byte(a))
// }
// return argsBytes
// }

func (ev *Event) encryptPayload() ([]byte, error) {
content := &pb.Content{
Expand Down
1 change: 1 addition & 0 deletions receipt.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:unparam
package main

import (
Expand Down
12 changes: 6 additions & 6 deletions verify.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//nolint:unparam
package main

import (
"context"
"encoding/binary"
"encoding/json"
"fmt"
"math/big"
Expand Down Expand Up @@ -145,10 +145,10 @@ func addressArrayContains(addrs []string, address []byte) bool {
return false
}

func uint64ToBytesInBigEndian(i uint64) []byte {
bytes := make([]byte, 8)
// func uint64ToBytesInBigEndian(i uint64) []byte {
// bytes := make([]byte, 8)

binary.BigEndian.PutUint64(bytes, i)
// binary.BigEndian.PutUint64(bytes, i)

return bytes
}
// return bytes
// }