/
types.go
47 lines (40 loc) · 1.17 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package types
import (
"crypto/sha256"
"encoding/hex"
"github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/datachainlab/cross/x/core/auth/types"
txtypes "github.com/datachainlab/cross/x/core/tx/types"
)
type ID string
type ClientID string
type MSPID string
// NewContractCallRequest creates a new instance of ContractCallRequest
func NewContractCallRequest(method string, args ...string) ContractCallRequest {
return ContractCallRequest{
Method: method,
Args: args,
}
}
// ContractCallInfo converts the ContractCallRequest to a ContractCallInfo
func (r ContractCallRequest) ContractCallInfo(m codec.Codec) txtypes.ContractCallInfo {
return m.MustMarshalJSON(&r)
}
// NOTE: This ID is an example. Do not use in production.
func NewID(mspID MSPID, clientID ClientID) (ID, error) {
fabAcc := FabricAccount{mspID, clientID}
fa, err := fabAcc.Marshal()
if err != nil {
return "", err
}
hash := sha256.Sum256(fa)
id := hex.EncodeToString(hash[:])
return ID(id), nil
}
func IDFromAccount(accountID authtypes.AccountID) ID {
encoded := hex.EncodeToString(accountID)
return ID(encoded)
}
func (i ID) Marshal() ([]byte, error) {
return hex.DecodeString(string(i))
}