Skip to content

Commit 4708194

Browse files
committed
add fetch and update helper functions
1 parent 4e4d073 commit 4708194

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/osnadmin/fetch.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package osnadmin
22

33
import (
4+
"context"
45
"crypto/tls"
56
"crypto/x509"
67
"fmt"
@@ -11,10 +12,14 @@ import (
1112
"google.golang.org/protobuf/proto"
1213
)
1314

14-
func Fetch(osnURL, channelID string, blockID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate) (*common.Block, error) {
15+
func Fetch(ctx context.Context, osnURL, channelID string, blockID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate) (*common.Block, error) {
1516
url := fmt.Sprintf("%s/participation/v1/channels/%s/blocks/%s", osnURL, channelID, blockID)
17+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
18+
if err != nil {
19+
return nil, fmt.Errorf("create request: %w", err)
20+
}
1621

17-
resp, err := httpGet(url, caCertPool, tlsClientCert)
22+
resp, err := httpDo(req, caCertPool, tlsClientCert)
1823
if err != nil {
1924
return nil, fmt.Errorf("process request: %w", err)
2025
}

pkg/channel/block.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package channel
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"crypto/x509"
57
"fmt"
68

9+
"github.com/hyperledger/fabric-admin-sdk/internal/osnadmin"
710
"github.com/hyperledger/fabric-admin-sdk/pkg/identity"
811
"github.com/hyperledger/fabric-admin-sdk/pkg/internal/proposal"
912

@@ -61,3 +64,7 @@ func getSignedProposal(ctx context.Context, connection grpc.ClientConnInterface,
6164

6265
return proposalResp, nil
6366
}
67+
68+
func GetBlock(ctx context.Context, osnURL, channelID, blockID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate) (*cb.Block, error) {
69+
return osnadmin.Fetch(ctx, osnURL, channelID, blockID, caCertPool, tlsClientCert)
70+
}

0 commit comments

Comments
 (0)