forked from hyperledger-archives/fabric-chaincode-evm
/
proxy_config.go
132 lines (118 loc) · 3.15 KB
/
proxy_config.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package helpers
import (
"fmt"
"os"
"path/filepath"
)
var configTemplate = `version: 1.0.0
client:
logging:
level: info
cryptoconfig:
path: %s
credentialStore:
path: "%s/state-store"
cryptoStore:
path: %s/msp
BCCSP:
security:
enabled: true
default:
provider: "SW"
hashAlgorithm: "SHA2"
softVerify: true
level: 256
channels:
%s:
peers:
peer0.org1.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
organizations:
org1:
mspid: Org1MSP
cryptoPath: peerOrganizations/org1.example.com/users/{username}@org1.example.com/msp
peers:
- peer0.org1.example.com
ordererorg:
mspID: OrdererMSP
cryptoPath: ordererOrganizations/example.com/users/{username}@example.com/msp
orderers:
orderer.example.com:
url: orderer.example.com:%d
grpcOptions:
ssl-target-name-override: orderer.example.com
keep-alive-time: 0s
keep-alive-timeout: 20s
keep-alive-permit: false
fail-fast: false
allow-insecure: false
tlsCACerts:
path: %s/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
peers:
peer0.org1.example.com:
url: peer0.org1.example.com:%d
grpcOptions:
ssl-target-name-override: peer0.org1.example.com
keep-alive-time: 0s
keep-alive-timeout: 20s
keep-alive-permit: false
fail-fast: false
allow-insecure: false
tlsCACerts:
path: %s/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem
entityMatchers:
peer:
- pattern: peer0.org1.example.(\w+)
urlSubstitutionExp: localhost:%d
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: peer0.org1.example.com
- pattern: (\w+).org1.example.(\w+):(\d+)
urlSubstitutionExp: localhost:$2
sslTargetOverrideUrlSubstitutionExp: $1.org1.example.com
mappedHost: $1.org1.example.com
- pattern: (\w+):%d
urlSubstitutionExp: localhost:%d
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: peer0.org1.example.com
orderer:
- pattern: (\w+):%d
urlSubstitutionExp: localhost:%d
sslTargetOverrideUrlSubstitutionExp: orderer.example.com
mappedHost: orderer.example.com
- pattern: (\w+).example.(\w+)
urlSubstitutionExp: localhost:%d
sslTargetOverrideUrlSubstitutionExp: orderer.example.com
mappedHost: orderer.example.com`
func CreateProxyConfig(testDir, channelName, cryptoConfigPath string, org1Peer0Port, ordererPort uint16) (string, error) {
config := fmt.Sprintf(configTemplate,
cryptoConfigPath,
testDir, testDir,
channelName,
ordererPort,
cryptoConfigPath,
org1Peer0Port, cryptoConfigPath,
org1Peer0Port,
org1Peer0Port,
org1Peer0Port,
ordererPort,
ordererPort,
ordererPort,
)
file, err := os.Create(filepath.Join(testDir, "web3-sdk-config.yaml"))
if err != nil {
return "", err
}
defer file.Close()
_, err = file.WriteString(config)
if err != nil {
return "", err
}
return file.Name(), nil
}