-
Notifications
You must be signed in to change notification settings - Fork 29
/
api.go
74 lines (65 loc) · 2.84 KB
/
api.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package client
import (
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-sdk-go/pkg/client/event"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
eventsapi "github.com/hyperledger/firefly-fabconnect/internal/events/api"
"github.com/hyperledger/firefly-fabconnect/internal/fabric/utils"
)
type ChaincodeSpec struct {
Type int `json:"type"`
Name string `json:"name"`
Version string `json:"version"`
}
type TxReceipt struct {
BlockNumber uint64 `json:"blockNumber"`
SignerMSP string `json:"signerMSP"`
Signer string `json:"signer"`
ChaincodeSpec ChaincodeSpec `json:"chaincode"`
TransactionID string `json:"transactionID"`
Status pb.TxValidationCode `json:"status"`
SourcePeer string `json:"peer"`
ResponsePayload []byte `json:"responsePayload"`
}
func (r *TxReceipt) IsSuccess() bool {
return r.Status == pb.TxValidationCode_VALID
}
type RegistrationWrapper struct {
registration fab.Registration
eventClient *event.Client
}
type RPCClient interface {
Invoke(channelID, signer, chaincodeName, method string, args []string, transientMap map[string]string, isInit bool) (*TxReceipt, error)
Query(channelID, signer, chaincodeName, method string, args []string, strongread bool) ([]byte, error)
QueryChainInfo(channelID, signer string) (*fab.BlockchainInfoResponse, error)
QueryBlock(channelID string, signer string, blocknumber uint64, blockhash []byte) (*utils.RawBlock, *utils.Block, error)
QueryBlockByTxID(channelID string, signer string, txID string) (*utils.RawBlock, *utils.Block, error)
QueryTransaction(channelID, signer, txID string) (map[string]interface{}, error)
SubscribeEvent(subInfo *eventsapi.SubscriptionInfo, since uint64) (*RegistrationWrapper, <-chan *fab.BlockEvent, <-chan *fab.CCEvent, error)
Unregister(*RegistrationWrapper)
Close() error
}
type IdentityClient interface {
GetSigningIdentity(name string) (msp.SigningIdentity, error)
GetClientOrg() string
AddSignerUpdateListener(SignerUpdateListener)
}
type SignerUpdateListener interface {
SignerUpdated(signer string)
}