forked from hyperledger-labs/yui-relayer
/
client-tx.go
51 lines (45 loc) · 1.45 KB
/
client-tx.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
48
49
50
51
package fabric
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
fabrictypes "github.com/hyperledger-labs/yui-fabric-ibc/x/ibc/light-clients/xx-fabric/types"
"github.com/mapdev33/yui-relayer/core"
)
// CreateMsgCreateClient creates a CreateClientMsg to this chain
func (pr *Prover) CreateMsgCreateClient(clientID string, dstHeader core.HeaderI, signer sdk.AccAddress) (*clienttypes.MsgCreateClient, error) {
h := dstHeader.(*fabrictypes.Header)
mspInfos, err := createMSPInitialClientState(h.MSPHeaders.Headers)
if err != nil {
return nil, err
}
clientState := &fabrictypes.ClientState{
Id: clientID,
LastChaincodeHeader: *h.ChaincodeHeader,
LastChaincodeInfo: *h.ChaincodeInfo,
LastMspInfos: *mspInfos,
}
consensusState := &fabrictypes.ConsensusState{
Timestamp: h.ChaincodeHeader.Sequence.Timestamp,
}
return clienttypes.NewMsgCreateClient(
clientState,
consensusState,
signer.String(),
)
}
func createMSPInitialClientState(headers []fabrictypes.MSPHeader) (*fabrictypes.MSPInfos, error) {
var infos fabrictypes.MSPInfos
for _, mh := range headers {
if mh.Type != fabrictypes.MSPHeaderTypeCreate {
return nil, fmt.Errorf("unexpected fabric type: %v", mh.Type)
}
infos.Infos = append(infos.Infos, fabrictypes.MSPInfo{
MSPID: mh.MSPID,
Config: mh.Config,
Policy: mh.Policy,
Freezed: false,
})
}
return &infos, nil
}