Commit 3ac49d2d authored by harrylee's avatar harrylee

add result type

parent 58cc8183
Pipeline #8459 failed with stages
...@@ -3,6 +3,8 @@ package pb ...@@ -3,6 +3,8 @@ package pb
import ( import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"strconv"
"strings"
"github.com/meshplus/bitxhub-kit/types" "github.com/meshplus/bitxhub-kit/types"
) )
...@@ -40,3 +42,68 @@ func (m *IBTP) Category() IBTP_Category { ...@@ -40,3 +42,68 @@ func (m *IBTP) Category() IBTP_Category {
} }
return IBTP_UNKNOWN return IBTP_UNKNOWN
} }
func (m *IBTP) ServicePair() string {
return fmt.Sprintf("%s-%s", m.From, m.To)
}
// ParseFrom should be called after CheckServiceID is called
func (m *IBTP) ParseFrom() (string, string, string) {
bxhID, chainID, serviceID, _ := ParseFullServiceID(m.From)
return bxhID, chainID, serviceID
}
// ParseTo should be called after CheckServiceID is called
func (m *IBTP) ParseTo() (string, string, string) {
bxhID, chainID, serviceID, _ := ParseFullServiceID(m.To)
return bxhID, chainID, serviceID
}
func (m *IBTP) CheckServiceID() error {
_, _, _, err := ParseFullServiceID(m.From)
if err != nil {
return err
}
_, _, _, err = ParseFullServiceID(m.To)
return err
}
func ParseFullServiceID(id string) (string, string, string, error) {
splits := strings.Split(id, ":")
if len(splits) != 3 {
return "", "", "", fmt.Errorf("invalid full service ID: %s", id)
}
return splits[0], splits[1], splits[2], nil
}
func ParseServicePair(servicePair string) (string, string, error) {
splits := strings.Split(servicePair, "-")
if len(splits) != 2 {
return "", "", fmt.Errorf("invalid service pair: %s", servicePair)
}
return splits[0], splits[1], nil
}
func ParseIBTPID(id string) (string, string, uint64, error) {
splits := strings.Split(id, "-")
if len(splits) != 3 {
return "", "", 0, fmt.Errorf("invalid IBTP ID: %s", id)
}
index, err := strconv.Atoi(splits[2])
if err != nil {
return "", "", 0, fmt.Errorf("invalid IBTP ID: %s", id)
}
return splits[0], splits[1], uint64(index), nil
}
func GenServicePair(from, to string) string {
return fmt.Sprintf("%s-%s", from, to)
}
This diff is collapsed.
...@@ -61,3 +61,7 @@ message content { ...@@ -61,3 +61,7 @@ message content {
message IBTPs { message IBTPs {
repeated IBTP ibtps = 1; repeated IBTP ibtps = 1;
} }
message result {
repeated bytes data = 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment