mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
merge into master
This commit is contained in:
commit
132236e7e1
130 changed files with 13253 additions and 3581 deletions
67
Jenkinsfile
vendored
67
Jenkinsfile
vendored
|
|
@ -6,8 +6,21 @@
|
||||||
// Pipeline script for fabric-samples
|
// Pipeline script for fabric-samples
|
||||||
|
|
||||||
node ('hyp-x') { // trigger build on x86_64 node
|
node ('hyp-x') { // trigger build on x86_64 node
|
||||||
|
timestamps {
|
||||||
|
try {
|
||||||
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
|
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
|
||||||
|
env.NODE_VER = "8.11.3" // NodeJs version
|
||||||
|
env.ARCH = "amd64"
|
||||||
|
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile && cat Makefile | grep "BASE_VERSION =" | cut -d "=" -f2').trim()
|
||||||
|
env.VERSION = "$VERSION" // BASE_VERSION from fabric Makefile
|
||||||
|
env.BASE_IMAGE_VER = sh(returnStdout: true, script: 'cat Makefile | grep BASEIMAGE_RELEASE= | cut -d "=" -f2').trim() // BASEIMAGE Version from fabric Makefile
|
||||||
|
env.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus
|
||||||
|
env.PROJECT_VERSION = "${VERSION}-stable"
|
||||||
|
env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version
|
||||||
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
|
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
|
||||||
|
env.GOPATH = "$WORKSPACE/gopath"
|
||||||
|
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"
|
||||||
|
|
||||||
def failure_stage = "none"
|
def failure_stage = "none"
|
||||||
// delete working directory
|
// delete working directory
|
||||||
deleteDir()
|
deleteDir()
|
||||||
|
|
@ -24,10 +37,11 @@ node ('hyp-x') { // trigger build on x86_64 node
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
failure_stage = "Fetch patchset"
|
failure_stage = "Fetch patchset"
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// clean environment and get env data
|
// clean environment and get env data
|
||||||
stage("Clean Environment - Get Env Info") {
|
stage("Clean Environment - Get Env Info") {
|
||||||
try {
|
try {
|
||||||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
||||||
|
|
@ -36,13 +50,15 @@ node ('hyp-x') { // trigger build on x86_64 node
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
failure_stage = "Clean Environment - Get Env Info"
|
failure_stage = "Clean Environment - Get Env Info"
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pull Third_party Images
|
||||||
// Pull Fabric Images
|
|
||||||
stage("Pull third_party images") {
|
stage("Pull third_party images") {
|
||||||
|
// making the output color coded
|
||||||
|
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
|
||||||
try {
|
try {
|
||||||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
||||||
sh './CI_Script.sh --pull_Thirdparty_Images'
|
sh './CI_Script.sh --pull_Thirdparty_Images'
|
||||||
|
|
@ -50,37 +66,33 @@ node ('hyp-x') { // trigger build on x86_64 node
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
failure_stage = "Pull third_party docker images"
|
failure_stage = "Pull third_party docker images"
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pull Fabric Images
|
// Pull Fabric, fabric-ca Images
|
||||||
stage("Pull fabric images") {
|
stage("Pull Docker images") {
|
||||||
|
// making the output color coded
|
||||||
|
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
|
||||||
try {
|
try {
|
||||||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
||||||
sh './CI_Script.sh --pull_Fabric_Images'
|
sh './CI_Script.sh --pull_Docker_Images'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
failure_stage = "Pull fabric docker images"
|
failure_stage = "Pull fabric, fabric-ca docker images"
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pull Fabric-ca
|
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode)
|
||||||
stage("Pull fabric-ca images") {
|
|
||||||
try {
|
|
||||||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
|
||||||
sh './CI_Script.sh --pull_Fabric_CA_Image'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
failure_stage = "Pull fabric-ca docker image"
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode, fabric-ca samples)
|
|
||||||
stage("Run byfn_eyfn Tests") {
|
stage("Run byfn_eyfn Tests") {
|
||||||
|
// making the output color coded
|
||||||
|
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
|
||||||
try {
|
try {
|
||||||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
||||||
sh './CI_Script.sh --byfn_eyfn_Tests'
|
sh './CI_Script.sh --byfn_eyfn_Tests'
|
||||||
|
|
@ -88,7 +100,22 @@ node ('hyp-x') { // trigger build on x86_64 node
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
failure_stage = "byfn_eyfn_Tests"
|
failure_stage = "byfn_eyfn_Tests"
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Archive the artifacts
|
||||||
|
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
|
||||||
|
// Sends notification to Rocket.Chat jenkins-robot channel
|
||||||
|
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
|
||||||
|
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
|
||||||
|
rocketSend channel: 'jenkins-robot', message: "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - (<${env.BUILD_URL}|Open>)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End Try block
|
||||||
|
}
|
||||||
|
// End Node block
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ intend to use to ensure alignment.
|
||||||
|
|
||||||
## Download Binaries and Docker Images
|
## Download Binaries and Docker Images
|
||||||
|
|
||||||
The [`scripts/bootstrap.sh`](https://github.com/hyperledger/fabric-samples/blob/release-1.1/scripts/bootstrap.sh)
|
The [`scripts/bootstrap.sh`](https://github.com/hyperledger/fabric-samples/blob/release-1.3/scripts/bootstrap.sh)
|
||||||
script will preload all of the requisite docker
|
script will preload all of the requisite docker
|
||||||
images for Hyperledger Fabric and tag them with the 'latest' tag. Optionally,
|
images for Hyperledger Fabric and tag them with the 'latest' tag. Optionally,
|
||||||
specify a version for fabric, fabric-ca and thirdparty images. Default versions
|
specify a version for fabric, fabric-ca and thirdparty images. Default versions
|
||||||
are 1.1.0, 1.1.0 and 0.4.7 respectively.
|
are 1.3.0, 1.3.0 and 0.4.13 respectively.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./scripts/bootstrap.sh [version] [ca version] [thirdparty_version]
|
./scripts/bootstrap.sh [version] [ca version] [thirdparty_version]
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ cd fabric-samples/balance-transfer
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
* This lauches the required network on your local machine
|
* This launches the required network on your local machine
|
||||||
* Installs the fabric-client and fabric-ca-client node modules
|
* Installs the fabric-client and fabric-ca-client node modules
|
||||||
* And, starts the node app on PORT 4000
|
* And, starts the node app on PORT 4000
|
||||||
|
|
||||||
|
|
@ -173,13 +173,40 @@ curl -s -X POST \
|
||||||
|
|
||||||
### Instantiate chaincode
|
### Instantiate chaincode
|
||||||
|
|
||||||
|
This is the endorsement policy defined during instantiation.
|
||||||
|
This policy can be fulfilled when members from both orgs sign the transaction proposal.
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
identities: [{
|
||||||
|
role: {
|
||||||
|
name: 'member',
|
||||||
|
mspId: 'Org1MSP'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: {
|
||||||
|
name: 'member',
|
||||||
|
mspId: 'Org2MSP'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
policy: {
|
||||||
|
'2-of': [{
|
||||||
|
'signed-by': 0
|
||||||
|
}, {
|
||||||
|
'signed-by': 1
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
http://localhost:4000/channels/mychannel/chaincodes \
|
http://localhost:4000/channels/mychannel/chaincodes \
|
||||||
-H "authorization: Bearer <put JSON Web Token here>" \
|
-H "authorization: Bearer <put JSON Web Token here>" \
|
||||||
-H "content-type: application/json" \
|
-H "content-type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
|
|
||||||
"chaincodeName":"mycc",
|
"chaincodeName":"mycc",
|
||||||
"chaincodeVersion":"v0",
|
"chaincodeVersion":"v0",
|
||||||
"chaincodeType": "golang",
|
"chaincodeType": "golang",
|
||||||
|
|
@ -190,13 +217,14 @@ curl -s -X POST \
|
||||||
|
|
||||||
### Invoke request
|
### Invoke request
|
||||||
|
|
||||||
|
This invoke request is signed by peers from both orgs, *org1* & *org2*.
|
||||||
```
|
```
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
http://localhost:4000/channels/mychannel/chaincodes/mycc \
|
http://localhost:4000/channels/mychannel/chaincodes/mycc \
|
||||||
-H "authorization: Bearer <put JSON Web Token here>" \
|
-H "authorization: Bearer <put JSON Web Token here>" \
|
||||||
-H "content-type: application/json" \
|
-H "content-type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
|
"peers": ["peer0.org1.example.com","peer0.org2.example.com"],
|
||||||
"fcn":"move",
|
"fcn":"move",
|
||||||
"args":["a","b","10"]
|
"args":["a","b","10"]
|
||||||
}'
|
}'
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ var hfc = require('fabric-client');
|
||||||
var helper = require('./app/helper.js');
|
var helper = require('./app/helper.js');
|
||||||
var createChannel = require('./app/create-channel.js');
|
var createChannel = require('./app/create-channel.js');
|
||||||
var join = require('./app/join-channel.js');
|
var join = require('./app/join-channel.js');
|
||||||
|
var updateAnchorPeers = require('./app/update-anchor-peers.js');
|
||||||
var install = require('./app/install-chaincode.js');
|
var install = require('./app/install-chaincode.js');
|
||||||
var instantiate = require('./app/instantiate-chaincode.js');
|
var instantiate = require('./app/instantiate-chaincode.js');
|
||||||
var invoke = require('./app/invoke-transaction.js');
|
var invoke = require('./app/invoke-transaction.js');
|
||||||
|
|
@ -179,6 +180,25 @@ app.post('/channels/:channelName/peers', async function(req, res) {
|
||||||
let message = await join.joinChannel(channelName, peers, req.username, req.orgname);
|
let message = await join.joinChannel(channelName, peers, req.username, req.orgname);
|
||||||
res.send(message);
|
res.send(message);
|
||||||
});
|
});
|
||||||
|
// Update anchor peers
|
||||||
|
app.post('/channels/:channelName/anchorpeers', async function(req, res) {
|
||||||
|
logger.debug('==================== UPDATE ANCHOR PEERS ==================');
|
||||||
|
var channelName = req.params.channelName;
|
||||||
|
var configUpdatePath = req.body.configUpdatePath;
|
||||||
|
logger.debug('Channel name : ' + channelName);
|
||||||
|
logger.debug('configUpdatePath : ' + configUpdatePath);
|
||||||
|
if (!channelName) {
|
||||||
|
res.json(getErrorMessage('\'channelName\''));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!configUpdatePath) {
|
||||||
|
res.json(getErrorMessage('\'configUpdatePath\''));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = await updateAnchorPeers.updateAnchorPeers(channelName, configUpdatePath, req.username, req.orgname);
|
||||||
|
res.send(message);
|
||||||
|
});
|
||||||
// Install chaincode on target peers
|
// Install chaincode on target peers
|
||||||
app.post('/chaincodes', async function(req, res) {
|
app.post('/chaincodes', async function(req, res) {
|
||||||
logger.debug('==================== INSTALL CHAINCODE ==================');
|
logger.debug('==================== INSTALL CHAINCODE ==================');
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
var util = require('util');
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,19 +20,9 @@ logger.setLevel('DEBUG');
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var copService = require('fabric-ca-client');
|
|
||||||
|
|
||||||
var hfc = require('fabric-client');
|
var hfc = require('fabric-client');
|
||||||
hfc.setLogger(logger);
|
hfc.setLogger(logger);
|
||||||
var ORGS = hfc.getConfigSetting('network-config');
|
|
||||||
|
|
||||||
var clients = {};
|
|
||||||
var channels = {};
|
|
||||||
var caClients = {};
|
|
||||||
|
|
||||||
var sleep = async function (sleep_time_ms) {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, sleep_time_ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getClientForOrg (userorg, username) {
|
async function getClientForOrg (userorg, username) {
|
||||||
logger.debug('getClientForOrg - ****** START %s %s', userorg, username)
|
logger.debug('getClientForOrg - ****** START %s %s', userorg, username)
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var config = require('../config.json');
|
|
||||||
var helper = require('./helper.js');
|
var helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('install-chaincode');
|
var logger = helper.getLogger('install-chaincode');
|
||||||
var tx_id = null;
|
|
||||||
|
|
||||||
var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
||||||
chaincodeVersion, chaincodeType, username, org_name) {
|
chaincodeVersion, chaincodeType, username, org_name) {
|
||||||
|
|
@ -34,7 +30,6 @@ var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
||||||
var client = await helper.getClientForOrg(org_name, username);
|
var client = await helper.getClientForOrg(org_name, username);
|
||||||
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
||||||
|
|
||||||
tx_id = client.newTransactionID(true); //get an admin transactionID
|
|
||||||
var request = {
|
var request = {
|
||||||
targets: peers,
|
targets: peers,
|
||||||
chaincodePath: chaincodePath,
|
chaincodePath: chaincodePath,
|
||||||
|
|
@ -76,7 +71,7 @@ var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error_message) {
|
if (!error_message) {
|
||||||
let message = util.format('Successfully install chaincode');
|
let message = util.format('Successfully installed chaincode');
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
// build a response to send back to the REST caller
|
// build a response to send back to the REST caller
|
||||||
let response = {
|
let response = {
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var hfc = require('fabric-client');
|
|
||||||
var helper = require('./helper.js');
|
var helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('instantiate-chaincode');
|
var logger = helper.getLogger('instantiate-chaincode');
|
||||||
|
|
||||||
|
|
@ -50,7 +47,19 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
chaincodeType: chaincodeType,
|
chaincodeType: chaincodeType,
|
||||||
chaincodeVersion: chaincodeVersion,
|
chaincodeVersion: chaincodeVersion,
|
||||||
args: args,
|
args: args,
|
||||||
txId: tx_id
|
txId: tx_id,
|
||||||
|
|
||||||
|
// Use this to demonstrate the following policy:
|
||||||
|
// The policy can be fulfilled when members from both orgs signed.
|
||||||
|
'endorsement-policy': {
|
||||||
|
identities: [
|
||||||
|
{ role: { name: 'member', mspId: 'Org1MSP' }},
|
||||||
|
{ role: { name: 'member', mspId: 'Org2MSP' }}
|
||||||
|
],
|
||||||
|
policy: {
|
||||||
|
'2-of':[{ 'signed-by': 0 }, { 'signed-by': 1 }]
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (functionName)
|
if (functionName)
|
||||||
|
|
@ -105,7 +114,7 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
clearTimeout(event_timeout);
|
clearTimeout(event_timeout);
|
||||||
|
|
||||||
if (code !== 'VALID') {
|
if (code !== 'VALID') {
|
||||||
let message = until.format('The chaincode instantiate transaction was invalid, code:%s',code);
|
let message = util.format('The chaincode instantiate transaction was invalid, code:%s',code);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
reject(new Error(message));
|
reject(new Error(message));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -175,7 +184,7 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
|
|
||||||
if (!error_message) {
|
if (!error_message) {
|
||||||
let message = util.format(
|
let message = util.format(
|
||||||
'Successfully instantiate chaingcode in organization %s to the channel \'%s\'',
|
'Successfully instantiate chaincode in organization %s to the channel \'%s\'',
|
||||||
org_name, channelName);
|
org_name, channelName);
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
// build a response to send back to the REST caller
|
// build a response to send back to the REST caller
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var hfc = require('fabric-client');
|
|
||||||
var helper = require('./helper.js');
|
var helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('invoke-chaincode');
|
var logger = helper.getLogger('invoke-chaincode');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
var helper = require('./helper.js');
|
var helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('Join-Channel');
|
var logger = helper.getLogger('Join-Channel');
|
||||||
|
|
@ -47,50 +45,10 @@ var joinChannel = async function(channel_name, peers, username, org_name) {
|
||||||
};
|
};
|
||||||
let genesis_block = await channel.getGenesisBlock(request);
|
let genesis_block = await channel.getGenesisBlock(request);
|
||||||
|
|
||||||
// tell each peer to join and wait for the event hub of each peer to tell us
|
// tell each peer to join and wait 10 seconds
|
||||||
// that the channel has been created on each peer
|
// for the channel to be created on each peer
|
||||||
var promises = [];
|
var promises = [];
|
||||||
var block_registration_numbers = [];
|
promises.push(new Promise(resolve => setTimeout(resolve, 10000)));
|
||||||
let event_hubs = client.getEventHubsForOrg(org_name);
|
|
||||||
event_hubs.forEach((eh) => {
|
|
||||||
let configBlockPromise = new Promise((resolve, reject) => {
|
|
||||||
let event_timeout = setTimeout(() => {
|
|
||||||
let message = 'REQUEST_TIMEOUT:' + eh._ep._endpoint.addr;
|
|
||||||
logger.error(message);
|
|
||||||
eh.disconnect();
|
|
||||||
reject(new Error(message));
|
|
||||||
}, 60000);
|
|
||||||
let block_registration_number = eh.registerBlockEvent((block) => {
|
|
||||||
clearTimeout(event_timeout);
|
|
||||||
// a peer may have more than one channel so
|
|
||||||
// we must check that this block came from the channel we
|
|
||||||
// asked the peer to join
|
|
||||||
if (block.data.data.length === 1) {
|
|
||||||
// Config block must only contain one transaction
|
|
||||||
var channel_header = block.data.data[0].payload.header.channel_header;
|
|
||||||
if (channel_header.channel_id === channel_name) {
|
|
||||||
let message = util.format('EventHub % has reported a block update for channel %s',eh._ep._endpoint.addr,channel_name);
|
|
||||||
logger.info(message)
|
|
||||||
resolve(message);
|
|
||||||
} else {
|
|
||||||
let message = util.format('Unknown channel block event received from %s',eh._ep._endpoint.addr);
|
|
||||||
logger.error(message);
|
|
||||||
reject(new Error(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, (err) => {
|
|
||||||
clearTimeout(event_timeout);
|
|
||||||
let message = 'Problem setting up the event hub :'+ err.toString();
|
|
||||||
logger.error(message);
|
|
||||||
reject(new Error(message));
|
|
||||||
});
|
|
||||||
// save the registration handle so able to deregister
|
|
||||||
block_registration_numbers.push(block_registration_number);
|
|
||||||
all_eventhubs.push(eh); //save for later so that we can shut it down
|
|
||||||
});
|
|
||||||
promises.push(configBlockPromise);
|
|
||||||
eh.connect(); //this opens the event stream that must be shutdown at some point with a disconnect()
|
|
||||||
});
|
|
||||||
|
|
||||||
let join_request = {
|
let join_request = {
|
||||||
targets: peers, //using the peer names which only is allowed when a connection profile is loaded
|
targets: peers, //using the peer names which only is allowed when a connection profile is loaded
|
||||||
|
|
@ -111,25 +69,11 @@ var joinChannel = async function(channel_name, peers, username, org_name) {
|
||||||
if(peer_result.response && peer_result.response.status == 200) {
|
if(peer_result.response && peer_result.response.status == 200) {
|
||||||
logger.info('Successfully joined peer to the channel %s',channel_name);
|
logger.info('Successfully joined peer to the channel %s',channel_name);
|
||||||
} else {
|
} else {
|
||||||
let message = util.format('Failed to joined peer to the channel %s',channel_name);
|
let message = util.format('Failed to join peer to the channel %s',channel_name);
|
||||||
error_message = message;
|
error_message = message;
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// now see what each of the event hubs reported
|
|
||||||
for(let i in results) {
|
|
||||||
let event_hub_result = results[i];
|
|
||||||
let event_hub = event_hubs[i];
|
|
||||||
let block_registration_number = block_registration_numbers[i];
|
|
||||||
logger.debug('Event results for event hub :%s',event_hub._ep._endpoint.addr);
|
|
||||||
if(typeof event_hub_result === 'string') {
|
|
||||||
logger.debug(event_hub_result);
|
|
||||||
} else {
|
|
||||||
if(!error_message) error_message = event_hub_result.toString();
|
|
||||||
logger.debug(event_hub_result.toString());
|
|
||||||
}
|
|
||||||
event_hub.unregisterBlockEvent(block_registration_number);
|
|
||||||
}
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logger.error('Failed to join channel due to error: ' + error.stack ? error.stack : error);
|
logger.error('Failed to join channel due to error: ' + error.stack ? error.stack : error);
|
||||||
error_message = error.toString();
|
error_message = error.toString();
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var hfc = require('fabric-client');
|
|
||||||
var helper = require('./helper.js');
|
var helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('Query');
|
var logger = helper.getLogger('Query');
|
||||||
|
|
||||||
|
|
@ -118,7 +115,7 @@ var getBlockByHash = async function(peer, channelName, hash, username, org_name)
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
let response_payload = await channel.queryBlockByHash(Buffer.from(hash), peer);
|
let response_payload = await channel.queryBlockByHash(Buffer.from(hash,'hex'), peer);
|
||||||
if (response_payload) {
|
if (response_payload) {
|
||||||
logger.debug(response_payload);
|
logger.debug(response_payload);
|
||||||
return response_payload;
|
return response_payload;
|
||||||
|
|
|
||||||
114
balance-transfer/app/update-anchor-peers.js
Normal file
114
balance-transfer/app/update-anchor-peers.js
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
/**
|
||||||
|
* Copyright Hitachi America, Ltd. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
var util = require('util');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
|
var helper = require('./helper.js');
|
||||||
|
var logger = helper.getLogger('update-anchor-peers');
|
||||||
|
|
||||||
|
var updateAnchorPeers = async function(channelName, configUpdatePath, username, org_name) {
|
||||||
|
logger.debug('\n====== Updating Anchor Peers on \'' + channelName + '\' ======\n');
|
||||||
|
var error_message = null;
|
||||||
|
try {
|
||||||
|
// first setup the client for this org
|
||||||
|
var client = await helper.getClientForOrg(org_name, username);
|
||||||
|
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
||||||
|
var channel = client.getChannel(channelName);
|
||||||
|
if(!channel) {
|
||||||
|
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
||||||
|
logger.error(message);
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read in the envelope for the channel config raw bytes
|
||||||
|
var envelope = fs.readFileSync(path.join(__dirname, configUpdatePath));
|
||||||
|
// extract the channel config bytes from the envelope to be signed
|
||||||
|
var channelConfig = client.extractChannelConfig(envelope);
|
||||||
|
|
||||||
|
//Acting as a client in the given organization provided with "orgName" param
|
||||||
|
// sign the channel config bytes as "endorsement", this is required by
|
||||||
|
// the orderer's channel creation policy
|
||||||
|
// this will use the admin identity assigned to the client when the connection profile was loaded
|
||||||
|
let signature = client.signChannelConfig(channelConfig);
|
||||||
|
|
||||||
|
let request = {
|
||||||
|
config: channelConfig,
|
||||||
|
signatures: [signature],
|
||||||
|
name: channelName,
|
||||||
|
txId: client.newTransactionID(true) // get an admin based transactionID
|
||||||
|
};
|
||||||
|
|
||||||
|
var promises = [];
|
||||||
|
let event_hubs = channel.getChannelEventHubsForOrg();
|
||||||
|
logger.debug('found %s eventhubs for this organization %s',event_hubs.length, org_name);
|
||||||
|
event_hubs.forEach((eh) => {
|
||||||
|
let anchorUpdateEventPromise = new Promise((resolve, reject) => {
|
||||||
|
logger.debug('anchorUpdateEventPromise - setting up event');
|
||||||
|
let event_timeout = setTimeout(() => {
|
||||||
|
let message = 'REQUEST_TIMEOUT:' + eh.getPeerAddr();
|
||||||
|
logger.error(message);
|
||||||
|
eh.disconnect();
|
||||||
|
}, 60000);
|
||||||
|
eh.registerBlockEvent((block) => {
|
||||||
|
logger.info('The config update has been committed on peer %s',eh.getPeerAddr());
|
||||||
|
clearTimeout(event_timeout);
|
||||||
|
resolve();
|
||||||
|
}, (err) => {
|
||||||
|
clearTimeout(event_timeout);
|
||||||
|
logger.error(err);
|
||||||
|
reject(err);
|
||||||
|
},
|
||||||
|
// the default for 'unregister' is true for block listeners
|
||||||
|
// so no real need to set here, however for 'disconnect'
|
||||||
|
// the default is false as most event hubs are long running
|
||||||
|
// in this use case we are using it only once
|
||||||
|
{unregister: true, disconnect: true}
|
||||||
|
);
|
||||||
|
eh.connect();
|
||||||
|
});
|
||||||
|
promises.push(anchorUpdateEventPromise);
|
||||||
|
});
|
||||||
|
|
||||||
|
var sendPromise = client.updateChannel(request);
|
||||||
|
// put the send to the orderer last so that the events get registered and
|
||||||
|
// are ready for the orderering and committing
|
||||||
|
promises.push(sendPromise);
|
||||||
|
let results = await Promise.all(promises);
|
||||||
|
logger.debug(util.format('------->>> R E S P O N S E : %j', results));
|
||||||
|
let response = results.pop(); // orderer results are last in the results
|
||||||
|
|
||||||
|
if (response && response.status === 'SUCCESS') {
|
||||||
|
logger.info('Successfully update anchor peers to the channel %s', channelName);
|
||||||
|
} else {
|
||||||
|
error_message = util.format('Failed to update anchor peers to the channel %s', channelName);
|
||||||
|
logger.error(error_message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to update anchor peers due to error: ' + error.stack ? error.stack : error);
|
||||||
|
error_message = error.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error_message) {
|
||||||
|
let message = util.format(
|
||||||
|
'Successfully update anchor peers in organization %s to the channel \'%s\'',
|
||||||
|
org_name, channelName);
|
||||||
|
logger.info(message);
|
||||||
|
let response = {
|
||||||
|
success: true,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
let message = util.format('Failed to update anchor peers. cause:%s',error_message);
|
||||||
|
logger.error(message);
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.updateAnchorPeers = updateAnchorPeers;
|
||||||
BIN
balance-transfer/artifacts/channel/Org1MSPanchors.tx
Normal file
BIN
balance-transfer/artifacts/channel/Org1MSPanchors.tx
Normal file
Binary file not shown.
BIN
balance-transfer/artifacts/channel/Org2MSPanchors.tx
Normal file
BIN
balance-transfer/artifacts/channel/Org2MSPanchors.tx
Normal file
Binary file not shown.
|
|
@ -74,6 +74,8 @@ services:
|
||||||
- CORE_PEER_ID=peer0.org1.example.com
|
- CORE_PEER_ID=peer0.org1.example.com
|
||||||
- CORE_PEER_LOCALMSPID=Org1MSP
|
- CORE_PEER_LOCALMSPID=Org1MSP
|
||||||
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
|
||||||
ports:
|
ports:
|
||||||
- 7051:7051
|
- 7051:7051
|
||||||
- 7053:7053
|
- 7053:7053
|
||||||
|
|
@ -91,6 +93,8 @@ services:
|
||||||
- CORE_PEER_ID=peer1.org1.example.com
|
- CORE_PEER_ID=peer1.org1.example.com
|
||||||
- CORE_PEER_LOCALMSPID=Org1MSP
|
- CORE_PEER_LOCALMSPID=Org1MSP
|
||||||
- CORE_PEER_ADDRESS=peer1.org1.example.com:7051
|
- CORE_PEER_ADDRESS=peer1.org1.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
|
||||||
ports:
|
ports:
|
||||||
- 7056:7051
|
- 7056:7051
|
||||||
- 7058:7053
|
- 7058:7053
|
||||||
|
|
@ -108,6 +112,8 @@ services:
|
||||||
- CORE_PEER_ID=peer0.org2.example.com
|
- CORE_PEER_ID=peer0.org2.example.com
|
||||||
- CORE_PEER_LOCALMSPID=Org2MSP
|
- CORE_PEER_LOCALMSPID=Org2MSP
|
||||||
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
|
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
|
||||||
ports:
|
ports:
|
||||||
- 8051:7051
|
- 8051:7051
|
||||||
- 8053:7053
|
- 8053:7053
|
||||||
|
|
@ -125,6 +131,8 @@ services:
|
||||||
- CORE_PEER_ID=peer1.org2.example.com
|
- CORE_PEER_ID=peer1.org2.example.com
|
||||||
- CORE_PEER_LOCALMSPID=Org2MSP
|
- CORE_PEER_LOCALMSPID=Org2MSP
|
||||||
- CORE_PEER_ADDRESS=peer1.org2.example.com:7051
|
- CORE_PEER_ADDRESS=peer1.org2.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
|
||||||
|
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:7051
|
||||||
ports:
|
ports:
|
||||||
- 8056:7051
|
- 8056:7051
|
||||||
- 8058:7053
|
- 8058:7053
|
||||||
|
|
|
||||||
|
|
@ -167,9 +167,6 @@ peers:
|
||||||
# this URL is used to send endorsement and query requests
|
# this URL is used to send endorsement and query requests
|
||||||
url: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:7051
|
url: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:7051
|
||||||
|
|
||||||
# this URL is used to connect the EventHub and registering event listeners
|
|
||||||
eventUrl: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:7053
|
|
||||||
|
|
||||||
grpcOptions:
|
grpcOptions:
|
||||||
ssl-target-name-override: peer0.org1.example.com
|
ssl-target-name-override: peer0.org1.example.com
|
||||||
tlsCACerts:
|
tlsCACerts:
|
||||||
|
|
@ -185,7 +182,6 @@ peers:
|
||||||
|
|
||||||
peer0.org2.example.com:
|
peer0.org2.example.com:
|
||||||
url: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:8051
|
url: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:8051
|
||||||
eventUrl: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:8053
|
|
||||||
grpcOptions:
|
grpcOptions:
|
||||||
ssl-target-name-override: peer0.org2.example.com
|
ssl-target-name-override: peer0.org2.example.com
|
||||||
tlsCACerts:
|
tlsCACerts:
|
||||||
|
|
@ -193,7 +189,6 @@ peers:
|
||||||
|
|
||||||
peer1.org2.example.com:
|
peer1.org2.example.com:
|
||||||
url: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:8056
|
url: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:8056
|
||||||
eventUrl: grpcs://ec2-13-59-99-140.us-east-2.compute.amazonaws.com:8058
|
|
||||||
grpcOptions:
|
grpcOptions:
|
||||||
ssl-target-name-override: peer1.org2.example.com
|
ssl-target-name-override: peer1.org2.example.com
|
||||||
tlsCACerts:
|
tlsCACerts:
|
||||||
|
|
|
||||||
|
|
@ -167,9 +167,6 @@ peers:
|
||||||
# this URL is used to send endorsement and query requests
|
# this URL is used to send endorsement and query requests
|
||||||
url: grpcs://localhost:7051
|
url: grpcs://localhost:7051
|
||||||
|
|
||||||
# this URL is used to connect the EventHub and registering event listeners
|
|
||||||
eventUrl: grpcs://localhost:7053
|
|
||||||
|
|
||||||
grpcOptions:
|
grpcOptions:
|
||||||
ssl-target-name-override: peer0.org1.example.com
|
ssl-target-name-override: peer0.org1.example.com
|
||||||
tlsCACerts:
|
tlsCACerts:
|
||||||
|
|
@ -177,7 +174,6 @@ peers:
|
||||||
|
|
||||||
peer1.org1.example.com:
|
peer1.org1.example.com:
|
||||||
url: grpcs://localhost:7056
|
url: grpcs://localhost:7056
|
||||||
eventUrl: grpcs://localhost:7058
|
|
||||||
grpcOptions:
|
grpcOptions:
|
||||||
ssl-target-name-override: peer1.org1.example.com
|
ssl-target-name-override: peer1.org1.example.com
|
||||||
tlsCACerts:
|
tlsCACerts:
|
||||||
|
|
@ -185,7 +181,6 @@ peers:
|
||||||
|
|
||||||
peer0.org2.example.com:
|
peer0.org2.example.com:
|
||||||
url: grpcs://localhost:8051
|
url: grpcs://localhost:8051
|
||||||
eventUrl: grpcs://localhost:8053
|
|
||||||
grpcOptions:
|
grpcOptions:
|
||||||
ssl-target-name-override: peer0.org2.example.com
|
ssl-target-name-override: peer0.org2.example.com
|
||||||
tlsCACerts:
|
tlsCACerts:
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,30 @@ curl -s -X POST \
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
echo "POST request Update anchor peers on Org1"
|
||||||
|
echo
|
||||||
|
curl -s -X POST \
|
||||||
|
http://localhost:4000/channels/mychannel/anchorpeers \
|
||||||
|
-H "authorization: Bearer $ORG1_TOKEN" \
|
||||||
|
-H "content-type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"configUpdatePath":"../artifacts/channel/Org1MSPanchors.tx"
|
||||||
|
}'
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "POST request Update anchor peers on Org2"
|
||||||
|
echo
|
||||||
|
curl -s -X POST \
|
||||||
|
http://localhost:4000/channels/mychannel/anchorpeers \
|
||||||
|
-H "authorization: Bearer $ORG2_TOKEN" \
|
||||||
|
-H "content-type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"configUpdatePath":"../artifacts/channel/Org2MSPanchors.tx"
|
||||||
|
}'
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
|
||||||
echo "POST Install chaincode on Org1"
|
echo "POST Install chaincode on Org1"
|
||||||
echo
|
echo
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
|
|
@ -144,7 +168,7 @@ curl -s -X POST \
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "POST instantiate chaincode on peer1 of Org1"
|
echo "POST instantiate chaincode on Org1"
|
||||||
echo
|
echo
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
http://localhost:4000/channels/mychannel/chaincodes \
|
http://localhost:4000/channels/mychannel/chaincodes \
|
||||||
|
|
@ -159,14 +183,14 @@ curl -s -X POST \
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "POST invoke chaincode on peers of Org1"
|
echo "POST invoke chaincode on peers of Org1 and Org2"
|
||||||
echo
|
echo
|
||||||
TRX_ID=$(curl -s -X POST \
|
TRX_ID=$(curl -s -X POST \
|
||||||
http://localhost:4000/channels/mychannel/chaincodes/mycc \
|
http://localhost:4000/channels/mychannel/chaincodes/mycc \
|
||||||
-H "authorization: Bearer $ORG1_TOKEN" \
|
-H "authorization: Bearer $ORG1_TOKEN" \
|
||||||
-H "content-type: application/json" \
|
-H "content-type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
|
"peers": ["peer0.org1.example.com","peer0.org2.example.com"],
|
||||||
"fcn":"move",
|
"fcn":"move",
|
||||||
"args":["a","b","10"]
|
"args":["a","b","10"]
|
||||||
}')
|
}')
|
||||||
|
|
@ -185,11 +209,13 @@ echo
|
||||||
|
|
||||||
echo "GET query Block by blockNumber"
|
echo "GET query Block by blockNumber"
|
||||||
echo
|
echo
|
||||||
curl -s -X GET \
|
BLOCK_INFO=$(curl -s -X GET \
|
||||||
"http://localhost:4000/channels/mychannel/blocks/1?peer=peer0.org1.example.com" \
|
"http://localhost:4000/channels/mychannel/blocks/1?peer=peer0.org1.example.com" \
|
||||||
-H "authorization: Bearer $ORG1_TOKEN" \
|
-H "authorization: Bearer $ORG1_TOKEN" \
|
||||||
-H "content-type: application/json"
|
-H "content-type: application/json")
|
||||||
echo
|
echo $BLOCK_INFO
|
||||||
|
# Assign previvious block hash to HASH
|
||||||
|
HASH=$(echo $BLOCK_INFO | jq -r ".header.previous_hash")
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "GET query Transaction by TransactionID"
|
echo "GET query Transaction by TransactionID"
|
||||||
|
|
@ -200,20 +226,17 @@ curl -s -X GET http://localhost:4000/channels/mychannel/transactions/$TRX_ID?pee
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
############################################################################
|
|
||||||
### TODO: What to pass to fetch the Block information
|
echo "GET query Block by Hash - Hash is $HASH"
|
||||||
############################################################################
|
echo
|
||||||
#echo "GET query Block by Hash"
|
curl -s -X GET \
|
||||||
#echo
|
"http://localhost:4000/channels/mychannel/blocks?hash=$HASH&peer=peer0.org1.example.com" \
|
||||||
#hash=????
|
-H "authorization: Bearer $ORG1_TOKEN" \
|
||||||
#curl -s -X GET \
|
-H "cache-control: no-cache" \
|
||||||
# "http://localhost:4000/channels/mychannel/blocks?hash=$hash&peer=peer1" \
|
-H "content-type: application/json" \
|
||||||
# -H "authorization: Bearer $ORG1_TOKEN" \
|
-H "x-access-token: $ORG1_TOKEN"
|
||||||
# -H "cache-control: no-cache" \
|
echo
|
||||||
# -H "content-type: application/json" \
|
echo
|
||||||
# -H "x-access-token: $ORG1_TOKEN"
|
|
||||||
#echo
|
|
||||||
#echo
|
|
||||||
|
|
||||||
echo "GET query ChainInfo"
|
echo "GET query ChainInfo"
|
||||||
echo
|
echo
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ cd fabric-samples/balance-transfer/typescript
|
||||||
```
|
```
|
||||||
|
|
||||||
This performs the following steps:
|
This performs the following steps:
|
||||||
* lauches the required network on your local machine
|
* launches the required network on your local machine
|
||||||
* installs the fabric-client and fabric-ca-client node modules
|
* installs the fabric-client and fabric-ca-client node modules
|
||||||
* starts the node app on PORT 4000
|
* starts the node app on PORT 4000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hyperledger/fabric/core/chaincode/lib/cid"
|
"github.com/hyperledger/fabric/core/chaincode/shim/ext/cid"
|
||||||
"github.com/hyperledger/fabric/core/chaincode/shim"
|
"github.com/hyperledger/fabric/core/chaincode/shim"
|
||||||
pb "github.com/hyperledger/fabric/protos/peer"
|
pb "github.com/hyperledger/fabric/protos/peer"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
3
chaincode/abac/go/vendor/github.com/golang/protobuf/LICENSE
generated
vendored
3
chaincode/abac/go/vendor/github.com/golang/protobuf/LICENSE
generated
vendored
|
|
@ -1,7 +1,4 @@
|
||||||
Go support for Protocol Buffers - Google's data interchange format
|
|
||||||
|
|
||||||
Copyright 2010 The Go Authors. All rights reserved.
|
Copyright 2010 The Go Authors. All rights reserved.
|
||||||
https://github.com/golang/protobuf
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
|
|
|
||||||
43
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/Makefile
generated
vendored
43
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/Makefile
generated
vendored
|
|
@ -1,43 +0,0 @@
|
||||||
# Go support for Protocol Buffers - Google's data interchange format
|
|
||||||
#
|
|
||||||
# Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
# https://github.com/golang/protobuf
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
|
||||||
# modification, are permitted provided that the following conditions are
|
|
||||||
# met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright
|
|
||||||
# notice, this list of conditions and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above
|
|
||||||
# copyright notice, this list of conditions and the following disclaimer
|
|
||||||
# in the documentation and/or other materials provided with the
|
|
||||||
# distribution.
|
|
||||||
# * Neither the name of Google Inc. nor the names of its
|
|
||||||
# contributors may be used to endorse or promote products derived from
|
|
||||||
# this software without specific prior written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
install:
|
|
||||||
go install
|
|
||||||
|
|
||||||
test: install generate-test-pbs
|
|
||||||
go test
|
|
||||||
|
|
||||||
|
|
||||||
generate-test-pbs:
|
|
||||||
make install
|
|
||||||
make -C testdata
|
|
||||||
protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto
|
|
||||||
make
|
|
||||||
46
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/clone.go
generated
vendored
46
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/clone.go
generated
vendored
|
|
@ -35,22 +35,39 @@
|
||||||
package proto
|
package proto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clone returns a deep copy of a protocol buffer.
|
// Clone returns a deep copy of a protocol buffer.
|
||||||
func Clone(pb Message) Message {
|
func Clone(src Message) Message {
|
||||||
in := reflect.ValueOf(pb)
|
in := reflect.ValueOf(src)
|
||||||
if in.IsNil() {
|
if in.IsNil() {
|
||||||
return pb
|
return src
|
||||||
}
|
}
|
||||||
|
|
||||||
out := reflect.New(in.Type().Elem())
|
out := reflect.New(in.Type().Elem())
|
||||||
// out is empty so a merge is a deep copy.
|
dst := out.Interface().(Message)
|
||||||
mergeStruct(out.Elem(), in.Elem())
|
Merge(dst, src)
|
||||||
return out.Interface().(Message)
|
return dst
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merger is the interface representing objects that can merge messages of the same type.
|
||||||
|
type Merger interface {
|
||||||
|
// Merge merges src into this message.
|
||||||
|
// Required and optional fields that are set in src will be set to that value in dst.
|
||||||
|
// Elements of repeated fields will be appended.
|
||||||
|
//
|
||||||
|
// Merge may panic if called with a different argument type than the receiver.
|
||||||
|
Merge(src Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// generatedMerger is the custom merge method that generated protos will have.
|
||||||
|
// We must add this method since a generate Merge method will conflict with
|
||||||
|
// many existing protos that have a Merge data field already defined.
|
||||||
|
type generatedMerger interface {
|
||||||
|
XXX_Merge(src Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge merges src into dst.
|
// Merge merges src into dst.
|
||||||
|
|
@ -58,17 +75,24 @@ func Clone(pb Message) Message {
|
||||||
// Elements of repeated fields will be appended.
|
// Elements of repeated fields will be appended.
|
||||||
// Merge panics if src and dst are not the same type, or if dst is nil.
|
// Merge panics if src and dst are not the same type, or if dst is nil.
|
||||||
func Merge(dst, src Message) {
|
func Merge(dst, src Message) {
|
||||||
|
if m, ok := dst.(Merger); ok {
|
||||||
|
m.Merge(src)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
in := reflect.ValueOf(src)
|
in := reflect.ValueOf(src)
|
||||||
out := reflect.ValueOf(dst)
|
out := reflect.ValueOf(dst)
|
||||||
if out.IsNil() {
|
if out.IsNil() {
|
||||||
panic("proto: nil destination")
|
panic("proto: nil destination")
|
||||||
}
|
}
|
||||||
if in.Type() != out.Type() {
|
if in.Type() != out.Type() {
|
||||||
// Explicit test prior to mergeStruct so that mistyped nils will fail
|
panic(fmt.Sprintf("proto.Merge(%T, %T) type mismatch", dst, src))
|
||||||
panic("proto: type mismatch")
|
|
||||||
}
|
}
|
||||||
if in.IsNil() {
|
if in.IsNil() {
|
||||||
// Merging nil into non-nil is a quiet no-op
|
return // Merge from nil src is a noop
|
||||||
|
}
|
||||||
|
if m, ok := dst.(generatedMerger); ok {
|
||||||
|
m.XXX_Merge(src)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mergeStruct(out.Elem(), in.Elem())
|
mergeStruct(out.Elem(), in.Elem())
|
||||||
|
|
@ -84,7 +108,7 @@ func mergeStruct(out, in reflect.Value) {
|
||||||
mergeAny(out.Field(i), in.Field(i), false, sprop.Prop[i])
|
mergeAny(out.Field(i), in.Field(i), false, sprop.Prop[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
if emIn, ok := extendable(in.Addr().Interface()); ok {
|
if emIn, err := extendable(in.Addr().Interface()); err == nil {
|
||||||
emOut, _ := extendable(out.Addr().Interface())
|
emOut, _ := extendable(out.Addr().Interface())
|
||||||
mIn, muIn := emIn.extensionsRead()
|
mIn, muIn := emIn.extensionsRead()
|
||||||
if mIn != nil {
|
if mIn != nil {
|
||||||
|
|
|
||||||
669
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/decode.go
generated
vendored
669
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/decode.go
generated
vendored
|
|
@ -39,8 +39,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// errOverflow is returned when an integer is too large to be represented.
|
// errOverflow is returned when an integer is too large to be represented.
|
||||||
|
|
@ -50,10 +48,6 @@ var errOverflow = errors.New("proto: integer overflow")
|
||||||
// wire type is encountered. It does not get returned to user code.
|
// wire type is encountered. It does not get returned to user code.
|
||||||
var ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
|
var ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
|
||||||
|
|
||||||
// The fundamental decoders that interpret bytes on the wire.
|
|
||||||
// Those that take integer types all return uint64 and are
|
|
||||||
// therefore of type valueDecoder.
|
|
||||||
|
|
||||||
// DecodeVarint reads a varint-encoded integer from the slice.
|
// DecodeVarint reads a varint-encoded integer from the slice.
|
||||||
// It returns the integer and the number of bytes consumed, or
|
// It returns the integer and the number of bytes consumed, or
|
||||||
// zero if there is not enough.
|
// zero if there is not enough.
|
||||||
|
|
@ -192,7 +186,6 @@ func (p *Buffer) DecodeVarint() (x uint64, err error) {
|
||||||
if b&0x80 == 0 {
|
if b&0x80 == 0 {
|
||||||
goto done
|
goto done
|
||||||
}
|
}
|
||||||
// x -= 0x80 << 63 // Always zero.
|
|
||||||
|
|
||||||
return 0, errOverflow
|
return 0, errOverflow
|
||||||
|
|
||||||
|
|
@ -267,9 +260,6 @@ func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are not ValueDecoders: they produce an array of bytes or a string.
|
|
||||||
// bytes, embedded messages
|
|
||||||
|
|
||||||
// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
|
// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
|
||||||
// This is the format used for the bytes protocol buffer
|
// This is the format used for the bytes protocol buffer
|
||||||
// type and for embedded messages.
|
// type and for embedded messages.
|
||||||
|
|
@ -311,81 +301,29 @@ func (p *Buffer) DecodeStringBytes() (s string, err error) {
|
||||||
return string(buf), nil
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
|
|
||||||
// If the protocol buffer has extensions, and the field matches, add it as an extension.
|
|
||||||
// Otherwise, if the XXX_unrecognized field exists, append the skipped data there.
|
|
||||||
func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base structPointer, unrecField field) error {
|
|
||||||
oi := o.index
|
|
||||||
|
|
||||||
err := o.skip(t, tag, wire)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !unrecField.IsValid() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr := structPointer_Bytes(base, unrecField)
|
|
||||||
|
|
||||||
// Add the skipped field to struct field
|
|
||||||
obuf := o.buf
|
|
||||||
|
|
||||||
o.buf = *ptr
|
|
||||||
o.EncodeVarint(uint64(tag<<3 | wire))
|
|
||||||
*ptr = append(o.buf, obuf[oi:o.index]...)
|
|
||||||
|
|
||||||
o.buf = obuf
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
|
|
||||||
func (o *Buffer) skip(t reflect.Type, tag, wire int) error {
|
|
||||||
|
|
||||||
var u uint64
|
|
||||||
var err error
|
|
||||||
|
|
||||||
switch wire {
|
|
||||||
case WireVarint:
|
|
||||||
_, err = o.DecodeVarint()
|
|
||||||
case WireFixed64:
|
|
||||||
_, err = o.DecodeFixed64()
|
|
||||||
case WireBytes:
|
|
||||||
_, err = o.DecodeRawBytes(false)
|
|
||||||
case WireFixed32:
|
|
||||||
_, err = o.DecodeFixed32()
|
|
||||||
case WireStartGroup:
|
|
||||||
for {
|
|
||||||
u, err = o.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
fwire := int(u & 0x7)
|
|
||||||
if fwire == WireEndGroup {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
ftag := int(u >> 3)
|
|
||||||
err = o.skip(t, ftag, fwire)
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("proto: can't skip unknown wire type %d for %s", wire, t)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshaler is the interface representing objects that can
|
// Unmarshaler is the interface representing objects that can
|
||||||
// unmarshal themselves. The method should reset the receiver before
|
// unmarshal themselves. The argument points to data that may be
|
||||||
// decoding starts. The argument points to data that may be
|
|
||||||
// overwritten, so implementations should not keep references to the
|
// overwritten, so implementations should not keep references to the
|
||||||
// buffer.
|
// buffer.
|
||||||
|
// Unmarshal implementations should not clear the receiver.
|
||||||
|
// Any unmarshaled data should be merged into the receiver.
|
||||||
|
// Callers of Unmarshal that do not want to retain existing data
|
||||||
|
// should Reset the receiver before calling Unmarshal.
|
||||||
type Unmarshaler interface {
|
type Unmarshaler interface {
|
||||||
Unmarshal([]byte) error
|
Unmarshal([]byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newUnmarshaler is the interface representing objects that can
|
||||||
|
// unmarshal themselves. The semantics are identical to Unmarshaler.
|
||||||
|
//
|
||||||
|
// This exists to support protoc-gen-go generated messages.
|
||||||
|
// The proto package will stop type-asserting to this interface in the future.
|
||||||
|
//
|
||||||
|
// DO NOT DEPEND ON THIS.
|
||||||
|
type newUnmarshaler interface {
|
||||||
|
XXX_Unmarshal([]byte) error
|
||||||
|
}
|
||||||
|
|
||||||
// Unmarshal parses the protocol buffer representation in buf and places the
|
// Unmarshal parses the protocol buffer representation in buf and places the
|
||||||
// decoded result in pb. If the struct underlying pb does not match
|
// decoded result in pb. If the struct underlying pb does not match
|
||||||
// the data in buf, the results can be unpredictable.
|
// the data in buf, the results can be unpredictable.
|
||||||
|
|
@ -395,7 +333,13 @@ type Unmarshaler interface {
|
||||||
// to preserve and append to existing data.
|
// to preserve and append to existing data.
|
||||||
func Unmarshal(buf []byte, pb Message) error {
|
func Unmarshal(buf []byte, pb Message) error {
|
||||||
pb.Reset()
|
pb.Reset()
|
||||||
return UnmarshalMerge(buf, pb)
|
if u, ok := pb.(newUnmarshaler); ok {
|
||||||
|
return u.XXX_Unmarshal(buf)
|
||||||
|
}
|
||||||
|
if u, ok := pb.(Unmarshaler); ok {
|
||||||
|
return u.Unmarshal(buf)
|
||||||
|
}
|
||||||
|
return NewBuffer(buf).Unmarshal(pb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalMerge parses the protocol buffer representation in buf and
|
// UnmarshalMerge parses the protocol buffer representation in buf and
|
||||||
|
|
@ -405,8 +349,16 @@ func Unmarshal(buf []byte, pb Message) error {
|
||||||
// UnmarshalMerge merges into existing data in pb.
|
// UnmarshalMerge merges into existing data in pb.
|
||||||
// Most code should use Unmarshal instead.
|
// Most code should use Unmarshal instead.
|
||||||
func UnmarshalMerge(buf []byte, pb Message) error {
|
func UnmarshalMerge(buf []byte, pb Message) error {
|
||||||
// If the object can unmarshal itself, let it.
|
if u, ok := pb.(newUnmarshaler); ok {
|
||||||
|
return u.XXX_Unmarshal(buf)
|
||||||
|
}
|
||||||
if u, ok := pb.(Unmarshaler); ok {
|
if u, ok := pb.(Unmarshaler); ok {
|
||||||
|
// NOTE: The history of proto have unfortunately been inconsistent
|
||||||
|
// whether Unmarshaler should or should not implicitly clear itself.
|
||||||
|
// Some implementations do, most do not.
|
||||||
|
// Thus, calling this here may or may not do what people want.
|
||||||
|
//
|
||||||
|
// See https://github.com/golang/protobuf/issues/424
|
||||||
return u.Unmarshal(buf)
|
return u.Unmarshal(buf)
|
||||||
}
|
}
|
||||||
return NewBuffer(buf).Unmarshal(pb)
|
return NewBuffer(buf).Unmarshal(pb)
|
||||||
|
|
@ -422,12 +374,17 @@ func (p *Buffer) DecodeMessage(pb Message) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeGroup reads a tag-delimited group from the Buffer.
|
// DecodeGroup reads a tag-delimited group from the Buffer.
|
||||||
|
// StartGroup tag is already consumed. This function consumes
|
||||||
|
// EndGroup tag.
|
||||||
func (p *Buffer) DecodeGroup(pb Message) error {
|
func (p *Buffer) DecodeGroup(pb Message) error {
|
||||||
typ, base, err := getbase(pb)
|
b := p.buf[p.index:]
|
||||||
if err != nil {
|
x, y := findEndGroup(b)
|
||||||
return err
|
if x < 0 {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
return p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), true, base)
|
err := Unmarshal(b[:x], pb)
|
||||||
|
p.index += y
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal parses the protocol buffer representation in the
|
// Unmarshal parses the protocol buffer representation in the
|
||||||
|
|
@ -438,533 +395,33 @@ func (p *Buffer) DecodeGroup(pb Message) error {
|
||||||
// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal.
|
// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal.
|
||||||
func (p *Buffer) Unmarshal(pb Message) error {
|
func (p *Buffer) Unmarshal(pb Message) error {
|
||||||
// If the object can unmarshal itself, let it.
|
// If the object can unmarshal itself, let it.
|
||||||
|
if u, ok := pb.(newUnmarshaler); ok {
|
||||||
|
err := u.XXX_Unmarshal(p.buf[p.index:])
|
||||||
|
p.index = len(p.buf)
|
||||||
|
return err
|
||||||
|
}
|
||||||
if u, ok := pb.(Unmarshaler); ok {
|
if u, ok := pb.(Unmarshaler); ok {
|
||||||
|
// NOTE: The history of proto have unfortunately been inconsistent
|
||||||
|
// whether Unmarshaler should or should not implicitly clear itself.
|
||||||
|
// Some implementations do, most do not.
|
||||||
|
// Thus, calling this here may or may not do what people want.
|
||||||
|
//
|
||||||
|
// See https://github.com/golang/protobuf/issues/424
|
||||||
err := u.Unmarshal(p.buf[p.index:])
|
err := u.Unmarshal(p.buf[p.index:])
|
||||||
p.index = len(p.buf)
|
p.index = len(p.buf)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
typ, base, err := getbase(pb)
|
// Slow workaround for messages that aren't Unmarshalers.
|
||||||
if err != nil {
|
// This includes some hand-coded .pb.go files and
|
||||||
return err
|
// bootstrap protos.
|
||||||
}
|
// TODO: fix all of those and then add Unmarshal to
|
||||||
|
// the Message interface. Then:
|
||||||
err = p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), false, base)
|
// The cast above and code below can be deleted.
|
||||||
|
// The old unmarshaler can be deleted.
|
||||||
if collectStats {
|
// Clients can call Unmarshal directly (can already do that, actually).
|
||||||
stats.Decode++
|
var info InternalMessageInfo
|
||||||
}
|
err := info.Unmarshal(pb, p.buf[p.index:])
|
||||||
|
p.index = len(p.buf)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// unmarshalType does the work of unmarshaling a structure.
|
|
||||||
func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group bool, base structPointer) error {
|
|
||||||
var state errorState
|
|
||||||
required, reqFields := prop.reqCount, uint64(0)
|
|
||||||
|
|
||||||
var err error
|
|
||||||
for err == nil && o.index < len(o.buf) {
|
|
||||||
oi := o.index
|
|
||||||
var u uint64
|
|
||||||
u, err = o.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
wire := int(u & 0x7)
|
|
||||||
if wire == WireEndGroup {
|
|
||||||
if is_group {
|
|
||||||
if required > 0 {
|
|
||||||
// Not enough information to determine the exact field.
|
|
||||||
// (See below.)
|
|
||||||
return &RequiredNotSetError{"{Unknown}"}
|
|
||||||
}
|
|
||||||
return nil // input is satisfied
|
|
||||||
}
|
|
||||||
return fmt.Errorf("proto: %s: wiretype end group for non-group", st)
|
|
||||||
}
|
|
||||||
tag := int(u >> 3)
|
|
||||||
if tag <= 0 {
|
|
||||||
return fmt.Errorf("proto: %s: illegal tag %d (wire type %d)", st, tag, wire)
|
|
||||||
}
|
|
||||||
fieldnum, ok := prop.decoderTags.get(tag)
|
|
||||||
if !ok {
|
|
||||||
// Maybe it's an extension?
|
|
||||||
if prop.extendable {
|
|
||||||
if e, _ := extendable(structPointer_Interface(base, st)); isExtensionField(e, int32(tag)) {
|
|
||||||
if err = o.skip(st, tag, wire); err == nil {
|
|
||||||
extmap := e.extensionsWrite()
|
|
||||||
ext := extmap[int32(tag)] // may be missing
|
|
||||||
ext.enc = append(ext.enc, o.buf[oi:o.index]...)
|
|
||||||
extmap[int32(tag)] = ext
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Maybe it's a oneof?
|
|
||||||
if prop.oneofUnmarshaler != nil {
|
|
||||||
m := structPointer_Interface(base, st).(Message)
|
|
||||||
// First return value indicates whether tag is a oneof field.
|
|
||||||
ok, err = prop.oneofUnmarshaler(m, tag, wire, o)
|
|
||||||
if err == ErrInternalBadWireType {
|
|
||||||
// Map the error to something more descriptive.
|
|
||||||
// Do the formatting here to save generated code space.
|
|
||||||
err = fmt.Errorf("bad wiretype for oneof field in %T", m)
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = o.skipAndSave(st, tag, wire, base, prop.unrecField)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
p := prop.Prop[fieldnum]
|
|
||||||
|
|
||||||
if p.dec == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", st, st.Field(fieldnum).Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
dec := p.dec
|
|
||||||
if wire != WireStartGroup && wire != p.WireType {
|
|
||||||
if wire == WireBytes && p.packedDec != nil {
|
|
||||||
// a packable field
|
|
||||||
dec = p.packedDec
|
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("proto: bad wiretype for field %s.%s: got wiretype %d, want %d", st, st.Field(fieldnum).Name, wire, p.WireType)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
decErr := dec(o, p, base)
|
|
||||||
if decErr != nil && !state.shouldContinue(decErr, p) {
|
|
||||||
err = decErr
|
|
||||||
}
|
|
||||||
if err == nil && p.Required {
|
|
||||||
// Successfully decoded a required field.
|
|
||||||
if tag <= 64 {
|
|
||||||
// use bitmap for fields 1-64 to catch field reuse.
|
|
||||||
var mask uint64 = 1 << uint64(tag-1)
|
|
||||||
if reqFields&mask == 0 {
|
|
||||||
// new required field
|
|
||||||
reqFields |= mask
|
|
||||||
required--
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// This is imprecise. It can be fooled by a required field
|
|
||||||
// with a tag > 64 that is encoded twice; that's very rare.
|
|
||||||
// A fully correct implementation would require allocating
|
|
||||||
// a data structure, which we would like to avoid.
|
|
||||||
required--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
if is_group {
|
|
||||||
return io.ErrUnexpectedEOF
|
|
||||||
}
|
|
||||||
if state.err != nil {
|
|
||||||
return state.err
|
|
||||||
}
|
|
||||||
if required > 0 {
|
|
||||||
// Not enough information to determine the exact field. If we use extra
|
|
||||||
// CPU, we could determine the field only if the missing required field
|
|
||||||
// has a tag <= 64 and we check reqFields.
|
|
||||||
return &RequiredNotSetError{"{Unknown}"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Individual type decoders
|
|
||||||
// For each,
|
|
||||||
// u is the decoded value,
|
|
||||||
// v is a pointer to the field (pointer) in the struct
|
|
||||||
|
|
||||||
// Sizes of the pools to allocate inside the Buffer.
|
|
||||||
// The goal is modest amortization and allocation
|
|
||||||
// on at least 16-byte boundaries.
|
|
||||||
const (
|
|
||||||
boolPoolSize = 16
|
|
||||||
uint32PoolSize = 8
|
|
||||||
uint64PoolSize = 4
|
|
||||||
)
|
|
||||||
|
|
||||||
// Decode a bool.
|
|
||||||
func (o *Buffer) dec_bool(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(o.bools) == 0 {
|
|
||||||
o.bools = make([]bool, boolPoolSize)
|
|
||||||
}
|
|
||||||
o.bools[0] = u != 0
|
|
||||||
*structPointer_Bool(base, p.field) = &o.bools[0]
|
|
||||||
o.bools = o.bools[1:]
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Buffer) dec_proto3_bool(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*structPointer_BoolVal(base, p.field) = u != 0
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode an int32.
|
|
||||||
func (o *Buffer) dec_int32(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
word32_Set(structPointer_Word32(base, p.field), o, uint32(u))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Buffer) dec_proto3_int32(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
word32Val_Set(structPointer_Word32Val(base, p.field), uint32(u))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode an int64.
|
|
||||||
func (o *Buffer) dec_int64(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
word64_Set(structPointer_Word64(base, p.field), o, u)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Buffer) dec_proto3_int64(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
word64Val_Set(structPointer_Word64Val(base, p.field), o, u)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a string.
|
|
||||||
func (o *Buffer) dec_string(p *Properties, base structPointer) error {
|
|
||||||
s, err := o.DecodeStringBytes()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*structPointer_String(base, p.field) = &s
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Buffer) dec_proto3_string(p *Properties, base structPointer) error {
|
|
||||||
s, err := o.DecodeStringBytes()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*structPointer_StringVal(base, p.field) = s
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of bytes ([]byte).
|
|
||||||
func (o *Buffer) dec_slice_byte(p *Properties, base structPointer) error {
|
|
||||||
b, err := o.DecodeRawBytes(true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*structPointer_Bytes(base, p.field) = b
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of bools ([]bool).
|
|
||||||
func (o *Buffer) dec_slice_bool(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v := structPointer_BoolSlice(base, p.field)
|
|
||||||
*v = append(*v, u != 0)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of bools ([]bool) in packed format.
|
|
||||||
func (o *Buffer) dec_slice_packed_bool(p *Properties, base structPointer) error {
|
|
||||||
v := structPointer_BoolSlice(base, p.field)
|
|
||||||
|
|
||||||
nn, err := o.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nb := int(nn) // number of bytes of encoded bools
|
|
||||||
fin := o.index + nb
|
|
||||||
if fin < o.index {
|
|
||||||
return errOverflow
|
|
||||||
}
|
|
||||||
|
|
||||||
y := *v
|
|
||||||
for o.index < fin {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
y = append(y, u != 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
*v = y
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of int32s ([]int32).
|
|
||||||
func (o *Buffer) dec_slice_int32(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
structPointer_Word32Slice(base, p.field).Append(uint32(u))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of int32s ([]int32) in packed format.
|
|
||||||
func (o *Buffer) dec_slice_packed_int32(p *Properties, base structPointer) error {
|
|
||||||
v := structPointer_Word32Slice(base, p.field)
|
|
||||||
|
|
||||||
nn, err := o.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nb := int(nn) // number of bytes of encoded int32s
|
|
||||||
|
|
||||||
fin := o.index + nb
|
|
||||||
if fin < o.index {
|
|
||||||
return errOverflow
|
|
||||||
}
|
|
||||||
for o.index < fin {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.Append(uint32(u))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of int64s ([]int64).
|
|
||||||
func (o *Buffer) dec_slice_int64(p *Properties, base structPointer) error {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
structPointer_Word64Slice(base, p.field).Append(u)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of int64s ([]int64) in packed format.
|
|
||||||
func (o *Buffer) dec_slice_packed_int64(p *Properties, base structPointer) error {
|
|
||||||
v := structPointer_Word64Slice(base, p.field)
|
|
||||||
|
|
||||||
nn, err := o.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nb := int(nn) // number of bytes of encoded int64s
|
|
||||||
|
|
||||||
fin := o.index + nb
|
|
||||||
if fin < o.index {
|
|
||||||
return errOverflow
|
|
||||||
}
|
|
||||||
for o.index < fin {
|
|
||||||
u, err := p.valDec(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.Append(u)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of strings ([]string).
|
|
||||||
func (o *Buffer) dec_slice_string(p *Properties, base structPointer) error {
|
|
||||||
s, err := o.DecodeStringBytes()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v := structPointer_StringSlice(base, p.field)
|
|
||||||
*v = append(*v, s)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of slice of bytes ([][]byte).
|
|
||||||
func (o *Buffer) dec_slice_slice_byte(p *Properties, base structPointer) error {
|
|
||||||
b, err := o.DecodeRawBytes(true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v := structPointer_BytesSlice(base, p.field)
|
|
||||||
*v = append(*v, b)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a map field.
|
|
||||||
func (o *Buffer) dec_new_map(p *Properties, base structPointer) error {
|
|
||||||
raw, err := o.DecodeRawBytes(false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
oi := o.index // index at the end of this map entry
|
|
||||||
o.index -= len(raw) // move buffer back to start of map entry
|
|
||||||
|
|
||||||
mptr := structPointer_NewAt(base, p.field, p.mtype) // *map[K]V
|
|
||||||
if mptr.Elem().IsNil() {
|
|
||||||
mptr.Elem().Set(reflect.MakeMap(mptr.Type().Elem()))
|
|
||||||
}
|
|
||||||
v := mptr.Elem() // map[K]V
|
|
||||||
|
|
||||||
// Prepare addressable doubly-indirect placeholders for the key and value types.
|
|
||||||
// See enc_new_map for why.
|
|
||||||
keyptr := reflect.New(reflect.PtrTo(p.mtype.Key())).Elem() // addressable *K
|
|
||||||
keybase := toStructPointer(keyptr.Addr()) // **K
|
|
||||||
|
|
||||||
var valbase structPointer
|
|
||||||
var valptr reflect.Value
|
|
||||||
switch p.mtype.Elem().Kind() {
|
|
||||||
case reflect.Slice:
|
|
||||||
// []byte
|
|
||||||
var dummy []byte
|
|
||||||
valptr = reflect.ValueOf(&dummy) // *[]byte
|
|
||||||
valbase = toStructPointer(valptr) // *[]byte
|
|
||||||
case reflect.Ptr:
|
|
||||||
// message; valptr is **Msg; need to allocate the intermediate pointer
|
|
||||||
valptr = reflect.New(reflect.PtrTo(p.mtype.Elem())).Elem() // addressable *V
|
|
||||||
valptr.Set(reflect.New(valptr.Type().Elem()))
|
|
||||||
valbase = toStructPointer(valptr)
|
|
||||||
default:
|
|
||||||
// everything else
|
|
||||||
valptr = reflect.New(reflect.PtrTo(p.mtype.Elem())).Elem() // addressable *V
|
|
||||||
valbase = toStructPointer(valptr.Addr()) // **V
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode.
|
|
||||||
// This parses a restricted wire format, namely the encoding of a message
|
|
||||||
// with two fields. See enc_new_map for the format.
|
|
||||||
for o.index < oi {
|
|
||||||
// tagcode for key and value properties are always a single byte
|
|
||||||
// because they have tags 1 and 2.
|
|
||||||
tagcode := o.buf[o.index]
|
|
||||||
o.index++
|
|
||||||
switch tagcode {
|
|
||||||
case p.mkeyprop.tagcode[0]:
|
|
||||||
if err := p.mkeyprop.dec(o, p.mkeyprop, keybase); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case p.mvalprop.tagcode[0]:
|
|
||||||
if err := p.mvalprop.dec(o, p.mvalprop, valbase); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// TODO: Should we silently skip this instead?
|
|
||||||
return fmt.Errorf("proto: bad map data tag %d", raw[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keyelem, valelem := keyptr.Elem(), valptr.Elem()
|
|
||||||
if !keyelem.IsValid() {
|
|
||||||
keyelem = reflect.Zero(p.mtype.Key())
|
|
||||||
}
|
|
||||||
if !valelem.IsValid() {
|
|
||||||
valelem = reflect.Zero(p.mtype.Elem())
|
|
||||||
}
|
|
||||||
|
|
||||||
v.SetMapIndex(keyelem, valelem)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a group.
|
|
||||||
func (o *Buffer) dec_struct_group(p *Properties, base structPointer) error {
|
|
||||||
bas := structPointer_GetStructPointer(base, p.field)
|
|
||||||
if structPointer_IsNil(bas) {
|
|
||||||
// allocate new nested message
|
|
||||||
bas = toStructPointer(reflect.New(p.stype))
|
|
||||||
structPointer_SetStructPointer(base, p.field, bas)
|
|
||||||
}
|
|
||||||
return o.unmarshalType(p.stype, p.sprop, true, bas)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode an embedded message.
|
|
||||||
func (o *Buffer) dec_struct_message(p *Properties, base structPointer) (err error) {
|
|
||||||
raw, e := o.DecodeRawBytes(false)
|
|
||||||
if e != nil {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
bas := structPointer_GetStructPointer(base, p.field)
|
|
||||||
if structPointer_IsNil(bas) {
|
|
||||||
// allocate new nested message
|
|
||||||
bas = toStructPointer(reflect.New(p.stype))
|
|
||||||
structPointer_SetStructPointer(base, p.field, bas)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the object can unmarshal itself, let it.
|
|
||||||
if p.isUnmarshaler {
|
|
||||||
iv := structPointer_Interface(bas, p.stype)
|
|
||||||
return iv.(Unmarshaler).Unmarshal(raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
obuf := o.buf
|
|
||||||
oi := o.index
|
|
||||||
o.buf = raw
|
|
||||||
o.index = 0
|
|
||||||
|
|
||||||
err = o.unmarshalType(p.stype, p.sprop, false, bas)
|
|
||||||
o.buf = obuf
|
|
||||||
o.index = oi
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of embedded messages.
|
|
||||||
func (o *Buffer) dec_slice_struct_message(p *Properties, base structPointer) error {
|
|
||||||
return o.dec_slice_struct(p, false, base)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of embedded groups.
|
|
||||||
func (o *Buffer) dec_slice_struct_group(p *Properties, base structPointer) error {
|
|
||||||
return o.dec_slice_struct(p, true, base)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode a slice of structs ([]*struct).
|
|
||||||
func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base structPointer) error {
|
|
||||||
v := reflect.New(p.stype)
|
|
||||||
bas := toStructPointer(v)
|
|
||||||
structPointer_StructPointerSlice(base, p.field).Append(bas)
|
|
||||||
|
|
||||||
if is_group {
|
|
||||||
err := o.unmarshalType(p.stype, p.sprop, is_group, bas)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
raw, err := o.DecodeRawBytes(false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the object can unmarshal itself, let it.
|
|
||||||
if p.isUnmarshaler {
|
|
||||||
iv := v.Interface()
|
|
||||||
return iv.(Unmarshaler).Unmarshal(raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
obuf := o.buf
|
|
||||||
oi := o.index
|
|
||||||
o.buf = raw
|
|
||||||
o.index = 0
|
|
||||||
|
|
||||||
err = o.unmarshalType(p.stype, p.sprop, is_group, bas)
|
|
||||||
|
|
||||||
o.buf = obuf
|
|
||||||
o.index = oi
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/deprecated.go
generated
vendored
Normal file
38
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/deprecated.go
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Go support for Protocol Buffers - Google's data interchange format
|
||||||
|
//
|
||||||
|
// Copyright 2018 The Go Authors. All rights reserved.
|
||||||
|
// https://github.com/golang/protobuf
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following disclaimer
|
||||||
|
// in the documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
// * Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
package proto
|
||||||
|
|
||||||
|
// Deprecated: do not use.
|
||||||
|
type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
|
||||||
|
|
||||||
|
// Deprecated: do not use.
|
||||||
|
func GetStats() Stats { return Stats{} }
|
||||||
201
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/discard.go
generated
vendored
201
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/discard.go
generated
vendored
|
|
@ -35,8 +35,14 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type generatedDiscarder interface {
|
||||||
|
XXX_DiscardUnknown()
|
||||||
|
}
|
||||||
|
|
||||||
// DiscardUnknown recursively discards all unknown fields from this message
|
// DiscardUnknown recursively discards all unknown fields from this message
|
||||||
// and all embedded messages.
|
// and all embedded messages.
|
||||||
//
|
//
|
||||||
|
|
@ -49,9 +55,202 @@ import (
|
||||||
// For proto2 messages, the unknown fields of message extensions are only
|
// For proto2 messages, the unknown fields of message extensions are only
|
||||||
// discarded from messages that have been accessed via GetExtension.
|
// discarded from messages that have been accessed via GetExtension.
|
||||||
func DiscardUnknown(m Message) {
|
func DiscardUnknown(m Message) {
|
||||||
|
if m, ok := m.(generatedDiscarder); ok {
|
||||||
|
m.XXX_DiscardUnknown()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO: Dynamically populate a InternalMessageInfo for legacy messages,
|
||||||
|
// but the master branch has no implementation for InternalMessageInfo,
|
||||||
|
// so it would be more work to replicate that approach.
|
||||||
discardLegacy(m)
|
discardLegacy(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiscardUnknown recursively discards all unknown fields.
|
||||||
|
func (a *InternalMessageInfo) DiscardUnknown(m Message) {
|
||||||
|
di := atomicLoadDiscardInfo(&a.discard)
|
||||||
|
if di == nil {
|
||||||
|
di = getDiscardInfo(reflect.TypeOf(m).Elem())
|
||||||
|
atomicStoreDiscardInfo(&a.discard, di)
|
||||||
|
}
|
||||||
|
di.discard(toPointer(&m))
|
||||||
|
}
|
||||||
|
|
||||||
|
type discardInfo struct {
|
||||||
|
typ reflect.Type
|
||||||
|
|
||||||
|
initialized int32 // 0: only typ is valid, 1: everything is valid
|
||||||
|
lock sync.Mutex
|
||||||
|
|
||||||
|
fields []discardFieldInfo
|
||||||
|
unrecognized field
|
||||||
|
}
|
||||||
|
|
||||||
|
type discardFieldInfo struct {
|
||||||
|
field field // Offset of field, guaranteed to be valid
|
||||||
|
discard func(src pointer)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
discardInfoMap = map[reflect.Type]*discardInfo{}
|
||||||
|
discardInfoLock sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
|
func getDiscardInfo(t reflect.Type) *discardInfo {
|
||||||
|
discardInfoLock.Lock()
|
||||||
|
defer discardInfoLock.Unlock()
|
||||||
|
di := discardInfoMap[t]
|
||||||
|
if di == nil {
|
||||||
|
di = &discardInfo{typ: t}
|
||||||
|
discardInfoMap[t] = di
|
||||||
|
}
|
||||||
|
return di
|
||||||
|
}
|
||||||
|
|
||||||
|
func (di *discardInfo) discard(src pointer) {
|
||||||
|
if src.isNil() {
|
||||||
|
return // Nothing to do.
|
||||||
|
}
|
||||||
|
|
||||||
|
if atomic.LoadInt32(&di.initialized) == 0 {
|
||||||
|
di.computeDiscardInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fi := range di.fields {
|
||||||
|
sfp := src.offset(fi.field)
|
||||||
|
fi.discard(sfp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// For proto2 messages, only discard unknown fields in message extensions
|
||||||
|
// that have been accessed via GetExtension.
|
||||||
|
if em, err := extendable(src.asPointerTo(di.typ).Interface()); err == nil {
|
||||||
|
// Ignore lock since DiscardUnknown is not concurrency safe.
|
||||||
|
emm, _ := em.extensionsRead()
|
||||||
|
for _, mx := range emm {
|
||||||
|
if m, ok := mx.value.(Message); ok {
|
||||||
|
DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if di.unrecognized.IsValid() {
|
||||||
|
*src.offset(di.unrecognized).toBytes() = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (di *discardInfo) computeDiscardInfo() {
|
||||||
|
di.lock.Lock()
|
||||||
|
defer di.lock.Unlock()
|
||||||
|
if di.initialized != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := di.typ
|
||||||
|
n := t.NumField()
|
||||||
|
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
f := t.Field(i)
|
||||||
|
if strings.HasPrefix(f.Name, "XXX_") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dfi := discardFieldInfo{field: toField(&f)}
|
||||||
|
tf := f.Type
|
||||||
|
|
||||||
|
// Unwrap tf to get its most basic type.
|
||||||
|
var isPointer, isSlice bool
|
||||||
|
if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
|
||||||
|
isSlice = true
|
||||||
|
tf = tf.Elem()
|
||||||
|
}
|
||||||
|
if tf.Kind() == reflect.Ptr {
|
||||||
|
isPointer = true
|
||||||
|
tf = tf.Elem()
|
||||||
|
}
|
||||||
|
if isPointer && isSlice && tf.Kind() != reflect.Struct {
|
||||||
|
panic(fmt.Sprintf("%v.%s cannot be a slice of pointers to primitive types", t, f.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tf.Kind() {
|
||||||
|
case reflect.Struct:
|
||||||
|
switch {
|
||||||
|
case !isPointer:
|
||||||
|
panic(fmt.Sprintf("%v.%s cannot be a direct struct value", t, f.Name))
|
||||||
|
case isSlice: // E.g., []*pb.T
|
||||||
|
di := getDiscardInfo(tf)
|
||||||
|
dfi.discard = func(src pointer) {
|
||||||
|
sps := src.getPointerSlice()
|
||||||
|
for _, sp := range sps {
|
||||||
|
if !sp.isNil() {
|
||||||
|
di.discard(sp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., *pb.T
|
||||||
|
di := getDiscardInfo(tf)
|
||||||
|
dfi.discard = func(src pointer) {
|
||||||
|
sp := src.getPointer()
|
||||||
|
if !sp.isNil() {
|
||||||
|
di.discard(sp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Map:
|
||||||
|
switch {
|
||||||
|
case isPointer || isSlice:
|
||||||
|
panic(fmt.Sprintf("%v.%s cannot be a pointer to a map or a slice of map values", t, f.Name))
|
||||||
|
default: // E.g., map[K]V
|
||||||
|
if tf.Elem().Kind() == reflect.Ptr { // Proto struct (e.g., *T)
|
||||||
|
dfi.discard = func(src pointer) {
|
||||||
|
sm := src.asPointerTo(tf).Elem()
|
||||||
|
if sm.Len() == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, key := range sm.MapKeys() {
|
||||||
|
val := sm.MapIndex(key)
|
||||||
|
DiscardUnknown(val.Interface().(Message))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dfi.discard = func(pointer) {} // Noop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Interface:
|
||||||
|
// Must be oneof field.
|
||||||
|
switch {
|
||||||
|
case isPointer || isSlice:
|
||||||
|
panic(fmt.Sprintf("%v.%s cannot be a pointer to a interface or a slice of interface values", t, f.Name))
|
||||||
|
default: // E.g., interface{}
|
||||||
|
// TODO: Make this faster?
|
||||||
|
dfi.discard = func(src pointer) {
|
||||||
|
su := src.asPointerTo(tf).Elem()
|
||||||
|
if !su.IsNil() {
|
||||||
|
sv := su.Elem().Elem().Field(0)
|
||||||
|
if sv.Kind() == reflect.Ptr && sv.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch sv.Type().Kind() {
|
||||||
|
case reflect.Ptr: // Proto struct (e.g., *T)
|
||||||
|
DiscardUnknown(sv.Interface().(Message))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
di.fields = append(di.fields, dfi)
|
||||||
|
}
|
||||||
|
|
||||||
|
di.unrecognized = invalidField
|
||||||
|
if f, ok := t.FieldByName("XXX_unrecognized"); ok {
|
||||||
|
if f.Type != reflect.TypeOf([]byte{}) {
|
||||||
|
panic("expected XXX_unrecognized to be of type []byte")
|
||||||
|
}
|
||||||
|
di.unrecognized = toField(&f)
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.StoreInt32(&di.initialized, 1)
|
||||||
|
}
|
||||||
|
|
||||||
func discardLegacy(m Message) {
|
func discardLegacy(m Message) {
|
||||||
v := reflect.ValueOf(m)
|
v := reflect.ValueOf(m)
|
||||||
if v.Kind() != reflect.Ptr || v.IsNil() {
|
if v.Kind() != reflect.Ptr || v.IsNil() {
|
||||||
|
|
@ -139,7 +338,7 @@ func discardLegacy(m Message) {
|
||||||
|
|
||||||
// For proto2 messages, only discard unknown fields in message extensions
|
// For proto2 messages, only discard unknown fields in message extensions
|
||||||
// that have been accessed via GetExtension.
|
// that have been accessed via GetExtension.
|
||||||
if em, ok := extendable(m); ok {
|
if em, err := extendable(m); err == nil {
|
||||||
// Ignore lock since discardLegacy is not concurrency safe.
|
// Ignore lock since discardLegacy is not concurrency safe.
|
||||||
emm, _ := em.extensionsRead()
|
emm, _ := em.extensionsRead()
|
||||||
for _, mx := range emm {
|
for _, mx := range emm {
|
||||||
|
|
|
||||||
1207
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/encode.go
generated
vendored
1207
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/encode.go
generated
vendored
File diff suppressed because it is too large
Load diff
30
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/equal.go
generated
vendored
30
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/equal.go
generated
vendored
|
|
@ -109,15 +109,6 @@ func equalStruct(v1, v2 reflect.Value) bool {
|
||||||
// set/unset mismatch
|
// set/unset mismatch
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
b1, ok := f1.Interface().(raw)
|
|
||||||
if ok {
|
|
||||||
b2 := f2.Interface().(raw)
|
|
||||||
// RawMessage
|
|
||||||
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
f1, f2 = f1.Elem(), f2.Elem()
|
f1, f2 = f1.Elem(), f2.Elem()
|
||||||
}
|
}
|
||||||
if !equalAny(f1, f2, sprop.Prop[i]) {
|
if !equalAny(f1, f2, sprop.Prop[i]) {
|
||||||
|
|
@ -146,11 +137,7 @@ func equalStruct(v1, v2 reflect.Value) bool {
|
||||||
|
|
||||||
u1 := uf.Bytes()
|
u1 := uf.Bytes()
|
||||||
u2 := v2.FieldByName("XXX_unrecognized").Bytes()
|
u2 := v2.FieldByName("XXX_unrecognized").Bytes()
|
||||||
if !bytes.Equal(u1, u2) {
|
return bytes.Equal(u1, u2)
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// v1 and v2 are known to have the same type.
|
// v1 and v2 are known to have the same type.
|
||||||
|
|
@ -261,6 +248,15 @@ func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool {
|
||||||
|
|
||||||
m1, m2 := e1.value, e2.value
|
m1, m2 := e1.value, e2.value
|
||||||
|
|
||||||
|
if m1 == nil && m2 == nil {
|
||||||
|
// Both have only encoded form.
|
||||||
|
if bytes.Equal(e1.enc, e2.enc) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// The bytes are different, but the extensions might still be
|
||||||
|
// equal. We need to decode them to compare.
|
||||||
|
}
|
||||||
|
|
||||||
if m1 != nil && m2 != nil {
|
if m1 != nil && m2 != nil {
|
||||||
// Both are unencoded.
|
// Both are unencoded.
|
||||||
if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2), nil) {
|
if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2), nil) {
|
||||||
|
|
@ -276,8 +272,12 @@ func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool {
|
||||||
desc = m[extNum]
|
desc = m[extNum]
|
||||||
}
|
}
|
||||||
if desc == nil {
|
if desc == nil {
|
||||||
|
// If both have only encoded form and the bytes are the same,
|
||||||
|
// it is handled above. We get here when the bytes are different.
|
||||||
|
// We don't know how to decode it, so just compare them as byte
|
||||||
|
// slices.
|
||||||
log.Printf("proto: don't know how to compare extension %d of %v", extNum, base)
|
log.Printf("proto: don't know how to compare extension %d of %v", extNum, base)
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if m1 == nil {
|
if m1 == nil {
|
||||||
|
|
|
||||||
204
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/extensions.go
generated
vendored
204
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/extensions.go
generated
vendored
|
|
@ -38,6 +38,7 @@ package proto
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -91,14 +92,29 @@ func (n notLocker) Unlock() {}
|
||||||
// extendable returns the extendableProto interface for the given generated proto message.
|
// extendable returns the extendableProto interface for the given generated proto message.
|
||||||
// If the proto message has the old extension format, it returns a wrapper that implements
|
// If the proto message has the old extension format, it returns a wrapper that implements
|
||||||
// the extendableProto interface.
|
// the extendableProto interface.
|
||||||
func extendable(p interface{}) (extendableProto, bool) {
|
func extendable(p interface{}) (extendableProto, error) {
|
||||||
if ep, ok := p.(extendableProto); ok {
|
switch p := p.(type) {
|
||||||
return ep, ok
|
case extendableProto:
|
||||||
|
if isNilPtr(p) {
|
||||||
|
return nil, fmt.Errorf("proto: nil %T is not extendable", p)
|
||||||
}
|
}
|
||||||
if ep, ok := p.(extendableProtoV1); ok {
|
return p, nil
|
||||||
return extensionAdapter{ep}, ok
|
case extendableProtoV1:
|
||||||
|
if isNilPtr(p) {
|
||||||
|
return nil, fmt.Errorf("proto: nil %T is not extendable", p)
|
||||||
}
|
}
|
||||||
return nil, false
|
return extensionAdapter{p}, nil
|
||||||
|
}
|
||||||
|
// Don't allocate a specific error containing %T:
|
||||||
|
// this is the hot path for Clone and MarshalText.
|
||||||
|
return nil, errNotExtendable
|
||||||
|
}
|
||||||
|
|
||||||
|
var errNotExtendable = errors.New("proto: not an extendable proto.Message")
|
||||||
|
|
||||||
|
func isNilPtr(x interface{}) bool {
|
||||||
|
v := reflect.ValueOf(x)
|
||||||
|
return v.Kind() == reflect.Ptr && v.IsNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX_InternalExtensions is an internal representation of proto extensions.
|
// XXX_InternalExtensions is an internal representation of proto extensions.
|
||||||
|
|
@ -143,9 +159,6 @@ func (e *XXX_InternalExtensions) extensionsRead() (map[int32]Extension, sync.Loc
|
||||||
return e.p.extensionMap, &e.p.mu
|
return e.p.extensionMap, &e.p.mu
|
||||||
}
|
}
|
||||||
|
|
||||||
var extendableProtoType = reflect.TypeOf((*extendableProto)(nil)).Elem()
|
|
||||||
var extendableProtoV1Type = reflect.TypeOf((*extendableProtoV1)(nil)).Elem()
|
|
||||||
|
|
||||||
// ExtensionDesc represents an extension specification.
|
// ExtensionDesc represents an extension specification.
|
||||||
// Used in generated code from the protocol compiler.
|
// Used in generated code from the protocol compiler.
|
||||||
type ExtensionDesc struct {
|
type ExtensionDesc struct {
|
||||||
|
|
@ -179,8 +192,8 @@ type Extension struct {
|
||||||
|
|
||||||
// SetRawExtension is for testing only.
|
// SetRawExtension is for testing only.
|
||||||
func SetRawExtension(base Message, id int32, b []byte) {
|
func SetRawExtension(base Message, id int32, b []byte) {
|
||||||
epb, ok := extendable(base)
|
epb, err := extendable(base)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
extmap := epb.extensionsWrite()
|
extmap := epb.extensionsWrite()
|
||||||
|
|
@ -205,7 +218,7 @@ func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
|
||||||
pbi = ea.extendableProtoV1
|
pbi = ea.extendableProtoV1
|
||||||
}
|
}
|
||||||
if a, b := reflect.TypeOf(pbi), reflect.TypeOf(extension.ExtendedType); a != b {
|
if a, b := reflect.TypeOf(pbi), reflect.TypeOf(extension.ExtendedType); a != b {
|
||||||
return errors.New("proto: bad extended type; " + b.String() + " does not extend " + a.String())
|
return fmt.Errorf("proto: bad extended type; %v does not extend %v", b, a)
|
||||||
}
|
}
|
||||||
// Check the range.
|
// Check the range.
|
||||||
if !isExtensionField(pb, extension.Field) {
|
if !isExtensionField(pb, extension.Field) {
|
||||||
|
|
@ -250,85 +263,11 @@ func extensionProperties(ed *ExtensionDesc) *Properties {
|
||||||
return prop
|
return prop
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode encodes any unmarshaled (unencoded) extensions in e.
|
|
||||||
func encodeExtensions(e *XXX_InternalExtensions) error {
|
|
||||||
m, mu := e.extensionsRead()
|
|
||||||
if m == nil {
|
|
||||||
return nil // fast path
|
|
||||||
}
|
|
||||||
mu.Lock()
|
|
||||||
defer mu.Unlock()
|
|
||||||
return encodeExtensionsMap(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// encode encodes any unmarshaled (unencoded) extensions in e.
|
|
||||||
func encodeExtensionsMap(m map[int32]Extension) error {
|
|
||||||
for k, e := range m {
|
|
||||||
if e.value == nil || e.desc == nil {
|
|
||||||
// Extension is only in its encoded form.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't skip extensions that have an encoded form set,
|
|
||||||
// because the extension value may have been mutated after
|
|
||||||
// the last time this function was called.
|
|
||||||
|
|
||||||
et := reflect.TypeOf(e.desc.ExtensionType)
|
|
||||||
props := extensionProperties(e.desc)
|
|
||||||
|
|
||||||
p := NewBuffer(nil)
|
|
||||||
// If e.value has type T, the encoder expects a *struct{ X T }.
|
|
||||||
// Pass a *T with a zero field and hope it all works out.
|
|
||||||
x := reflect.New(et)
|
|
||||||
x.Elem().Set(reflect.ValueOf(e.value))
|
|
||||||
if err := props.enc(p, props, toStructPointer(x)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
e.enc = p.buf
|
|
||||||
m[k] = e
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func extensionsSize(e *XXX_InternalExtensions) (n int) {
|
|
||||||
m, mu := e.extensionsRead()
|
|
||||||
if m == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
mu.Lock()
|
|
||||||
defer mu.Unlock()
|
|
||||||
return extensionsMapSize(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func extensionsMapSize(m map[int32]Extension) (n int) {
|
|
||||||
for _, e := range m {
|
|
||||||
if e.value == nil || e.desc == nil {
|
|
||||||
// Extension is only in its encoded form.
|
|
||||||
n += len(e.enc)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't skip extensions that have an encoded form set,
|
|
||||||
// because the extension value may have been mutated after
|
|
||||||
// the last time this function was called.
|
|
||||||
|
|
||||||
et := reflect.TypeOf(e.desc.ExtensionType)
|
|
||||||
props := extensionProperties(e.desc)
|
|
||||||
|
|
||||||
// If e.value has type T, the encoder expects a *struct{ X T }.
|
|
||||||
// Pass a *T with a zero field and hope it all works out.
|
|
||||||
x := reflect.New(et)
|
|
||||||
x.Elem().Set(reflect.ValueOf(e.value))
|
|
||||||
n += props.size(props, toStructPointer(x))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasExtension returns whether the given extension is present in pb.
|
// HasExtension returns whether the given extension is present in pb.
|
||||||
func HasExtension(pb Message, extension *ExtensionDesc) bool {
|
func HasExtension(pb Message, extension *ExtensionDesc) bool {
|
||||||
// TODO: Check types, field numbers, etc.?
|
// TODO: Check types, field numbers, etc.?
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
extmap, mu := epb.extensionsRead()
|
extmap, mu := epb.extensionsRead()
|
||||||
|
|
@ -336,15 +275,15 @@ func HasExtension(pb Message, extension *ExtensionDesc) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
_, ok = extmap[extension.Field]
|
_, ok := extmap[extension.Field]
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearExtension removes the given extension from pb.
|
// ClearExtension removes the given extension from pb.
|
||||||
func ClearExtension(pb Message, extension *ExtensionDesc) {
|
func ClearExtension(pb Message, extension *ExtensionDesc) {
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO: Check types, field numbers, etc.?
|
// TODO: Check types, field numbers, etc.?
|
||||||
|
|
@ -352,17 +291,27 @@ func ClearExtension(pb Message, extension *ExtensionDesc) {
|
||||||
delete(extmap, extension.Field)
|
delete(extmap, extension.Field)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExtension parses and returns the given extension of pb.
|
// GetExtension retrieves a proto2 extended field from pb.
|
||||||
// If the extension is not present and has no default value it returns ErrMissingExtension.
|
//
|
||||||
|
// If the descriptor is type complete (i.e., ExtensionDesc.ExtensionType is non-nil),
|
||||||
|
// then GetExtension parses the encoded field and returns a Go value of the specified type.
|
||||||
|
// If the field is not present, then the default value is returned (if one is specified),
|
||||||
|
// otherwise ErrMissingExtension is reported.
|
||||||
|
//
|
||||||
|
// If the descriptor is not type complete (i.e., ExtensionDesc.ExtensionType is nil),
|
||||||
|
// then GetExtension returns the raw encoded bytes of the field extension.
|
||||||
func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return nil, errors.New("proto: not an extendable proto")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if extension.ExtendedType != nil {
|
||||||
|
// can only check type if this is a complete descriptor
|
||||||
if err := checkExtensionTypes(epb, extension); err != nil {
|
if err := checkExtensionTypes(epb, extension); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emap, mu := epb.extensionsRead()
|
emap, mu := epb.extensionsRead()
|
||||||
if emap == nil {
|
if emap == nil {
|
||||||
|
|
@ -388,6 +337,11 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
||||||
return e.value, nil
|
return e.value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if extension.ExtensionType == nil {
|
||||||
|
// incomplete descriptor
|
||||||
|
return e.enc, nil
|
||||||
|
}
|
||||||
|
|
||||||
v, err := decodeExtension(e.enc, extension)
|
v, err := decodeExtension(e.enc, extension)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -405,6 +359,11 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
||||||
// defaultExtensionValue returns the default value for extension.
|
// defaultExtensionValue returns the default value for extension.
|
||||||
// If no default for an extension is defined ErrMissingExtension is returned.
|
// If no default for an extension is defined ErrMissingExtension is returned.
|
||||||
func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) {
|
func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) {
|
||||||
|
if extension.ExtensionType == nil {
|
||||||
|
// incomplete descriptor, so no default
|
||||||
|
return nil, ErrMissingExtension
|
||||||
|
}
|
||||||
|
|
||||||
t := reflect.TypeOf(extension.ExtensionType)
|
t := reflect.TypeOf(extension.ExtensionType)
|
||||||
props := extensionProperties(extension)
|
props := extensionProperties(extension)
|
||||||
|
|
||||||
|
|
@ -439,31 +398,28 @@ func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) {
|
||||||
|
|
||||||
// decodeExtension decodes an extension encoded in b.
|
// decodeExtension decodes an extension encoded in b.
|
||||||
func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
|
func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
|
||||||
o := NewBuffer(b)
|
|
||||||
|
|
||||||
t := reflect.TypeOf(extension.ExtensionType)
|
t := reflect.TypeOf(extension.ExtensionType)
|
||||||
|
unmarshal := typeUnmarshaler(t, extension.Tag)
|
||||||
props := extensionProperties(extension)
|
|
||||||
|
|
||||||
// t is a pointer to a struct, pointer to basic type or a slice.
|
// t is a pointer to a struct, pointer to basic type or a slice.
|
||||||
// Allocate a "field" to store the pointer/slice itself; the
|
// Allocate space to store the pointer/slice.
|
||||||
// pointer/slice will be stored here. We pass
|
|
||||||
// the address of this field to props.dec.
|
|
||||||
// This passes a zero field and a *t and lets props.dec
|
|
||||||
// interpret it as a *struct{ x t }.
|
|
||||||
value := reflect.New(t).Elem()
|
value := reflect.New(t).Elem()
|
||||||
|
|
||||||
|
var err error
|
||||||
for {
|
for {
|
||||||
// Discard wire type and field number varint. It isn't needed.
|
x, n := decodeVarint(b)
|
||||||
if _, err := o.DecodeVarint(); err != nil {
|
if n == 0 {
|
||||||
|
return nil, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b = b[n:]
|
||||||
|
wire := int(x) & 7
|
||||||
|
|
||||||
|
b, err = unmarshal(b, valToPointer(value.Addr()), wire)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := props.dec(o, props, toStructPointer(value.Addr())); err != nil {
|
if len(b) == 0 {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if o.index >= len(o.buf) {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -473,9 +429,9 @@ func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
|
||||||
// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
|
// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
|
||||||
// The returned slice has the same length as es; missing extensions will appear as nil elements.
|
// The returned slice has the same length as es; missing extensions will appear as nil elements.
|
||||||
func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
|
func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return nil, errors.New("proto: not an extendable proto")
|
return nil, err
|
||||||
}
|
}
|
||||||
extensions = make([]interface{}, len(es))
|
extensions = make([]interface{}, len(es))
|
||||||
for i, e := range es {
|
for i, e := range es {
|
||||||
|
|
@ -494,9 +450,9 @@ func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, e
|
||||||
// For non-registered extensions, ExtensionDescs returns an incomplete descriptor containing
|
// For non-registered extensions, ExtensionDescs returns an incomplete descriptor containing
|
||||||
// just the Field field, which defines the extension's field number.
|
// just the Field field, which defines the extension's field number.
|
||||||
func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
|
func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("proto: %T is not an extendable proto.Message", pb)
|
return nil, err
|
||||||
}
|
}
|
||||||
registeredExtensions := RegisteredExtensions(pb)
|
registeredExtensions := RegisteredExtensions(pb)
|
||||||
|
|
||||||
|
|
@ -523,16 +479,16 @@ func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
|
||||||
|
|
||||||
// SetExtension sets the specified extension of pb to the specified value.
|
// SetExtension sets the specified extension of pb to the specified value.
|
||||||
func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error {
|
func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error {
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return errors.New("proto: not an extendable proto")
|
return err
|
||||||
}
|
}
|
||||||
if err := checkExtensionTypes(epb, extension); err != nil {
|
if err := checkExtensionTypes(epb, extension); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
typ := reflect.TypeOf(extension.ExtensionType)
|
typ := reflect.TypeOf(extension.ExtensionType)
|
||||||
if typ != reflect.TypeOf(value) {
|
if typ != reflect.TypeOf(value) {
|
||||||
return errors.New("proto: bad extension value type")
|
return fmt.Errorf("proto: bad extension value type. got: %T, want: %T", value, extension.ExtensionType)
|
||||||
}
|
}
|
||||||
// nil extension values need to be caught early, because the
|
// nil extension values need to be caught early, because the
|
||||||
// encoder can't distinguish an ErrNil due to a nil extension
|
// encoder can't distinguish an ErrNil due to a nil extension
|
||||||
|
|
@ -550,8 +506,8 @@ func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error
|
||||||
|
|
||||||
// ClearAllExtensions clears all extensions from pb.
|
// ClearAllExtensions clears all extensions from pb.
|
||||||
func ClearAllExtensions(pb Message) {
|
func ClearAllExtensions(pb Message) {
|
||||||
epb, ok := extendable(pb)
|
epb, err := extendable(pb)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m := epb.extensionsWrite()
|
m := epb.extensionsWrite()
|
||||||
|
|
|
||||||
148
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/lib.go
generated
vendored
148
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/lib.go
generated
vendored
|
|
@ -273,6 +273,67 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RequiredNotSetError is an error type returned by either Marshal or Unmarshal.
|
||||||
|
// Marshal reports this when a required field is not initialized.
|
||||||
|
// Unmarshal reports this when a required field is missing from the wire data.
|
||||||
|
type RequiredNotSetError struct{ field string }
|
||||||
|
|
||||||
|
func (e *RequiredNotSetError) Error() string {
|
||||||
|
if e.field == "" {
|
||||||
|
return fmt.Sprintf("proto: required field not set")
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("proto: required field %q not set", e.field)
|
||||||
|
}
|
||||||
|
func (e *RequiredNotSetError) RequiredNotSet() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
type invalidUTF8Error struct{ field string }
|
||||||
|
|
||||||
|
func (e *invalidUTF8Error) Error() string {
|
||||||
|
if e.field == "" {
|
||||||
|
return "proto: invalid UTF-8 detected"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("proto: field %q contains invalid UTF-8", e.field)
|
||||||
|
}
|
||||||
|
func (e *invalidUTF8Error) InvalidUTF8() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// errInvalidUTF8 is a sentinel error to identify fields with invalid UTF-8.
|
||||||
|
// This error should not be exposed to the external API as such errors should
|
||||||
|
// be recreated with the field information.
|
||||||
|
var errInvalidUTF8 = &invalidUTF8Error{}
|
||||||
|
|
||||||
|
// isNonFatal reports whether the error is either a RequiredNotSet error
|
||||||
|
// or a InvalidUTF8 error.
|
||||||
|
func isNonFatal(err error) bool {
|
||||||
|
if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type nonFatal struct{ E error }
|
||||||
|
|
||||||
|
// Merge merges err into nf and reports whether it was successful.
|
||||||
|
// Otherwise it returns false for any fatal non-nil errors.
|
||||||
|
func (nf *nonFatal) Merge(err error) (ok bool) {
|
||||||
|
if err == nil {
|
||||||
|
return true // not an error
|
||||||
|
}
|
||||||
|
if !isNonFatal(err) {
|
||||||
|
return false // fatal error
|
||||||
|
}
|
||||||
|
if nf.E == nil {
|
||||||
|
nf.E = err // store first instance of non-fatal error
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Message is implemented by generated protocol buffer messages.
|
// Message is implemented by generated protocol buffer messages.
|
||||||
type Message interface {
|
type Message interface {
|
||||||
Reset()
|
Reset()
|
||||||
|
|
@ -280,26 +341,6 @@ type Message interface {
|
||||||
ProtoMessage()
|
ProtoMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stats records allocation details about the protocol buffer encoders
|
|
||||||
// and decoders. Useful for tuning the library itself.
|
|
||||||
type Stats struct {
|
|
||||||
Emalloc uint64 // mallocs in encode
|
|
||||||
Dmalloc uint64 // mallocs in decode
|
|
||||||
Encode uint64 // number of encodes
|
|
||||||
Decode uint64 // number of decodes
|
|
||||||
Chit uint64 // number of cache hits
|
|
||||||
Cmiss uint64 // number of cache misses
|
|
||||||
Size uint64 // number of sizes
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set to true to enable stats collection.
|
|
||||||
const collectStats = false
|
|
||||||
|
|
||||||
var stats Stats
|
|
||||||
|
|
||||||
// GetStats returns a copy of the global Stats structure.
|
|
||||||
func GetStats() Stats { return stats }
|
|
||||||
|
|
||||||
// A Buffer is a buffer manager for marshaling and unmarshaling
|
// A Buffer is a buffer manager for marshaling and unmarshaling
|
||||||
// protocol buffers. It may be reused between invocations to
|
// protocol buffers. It may be reused between invocations to
|
||||||
// reduce memory usage. It is not necessary to use a Buffer;
|
// reduce memory usage. It is not necessary to use a Buffer;
|
||||||
|
|
@ -309,16 +350,7 @@ type Buffer struct {
|
||||||
buf []byte // encode/decode byte stream
|
buf []byte // encode/decode byte stream
|
||||||
index int // read point
|
index int // read point
|
||||||
|
|
||||||
// pools of basic types to amortize allocation.
|
deterministic bool
|
||||||
bools []bool
|
|
||||||
uint32s []uint32
|
|
||||||
uint64s []uint64
|
|
||||||
|
|
||||||
// extra pools, only used with pointer_reflect.go
|
|
||||||
int32s []int32
|
|
||||||
int64s []int64
|
|
||||||
float32s []float32
|
|
||||||
float64s []float64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuffer allocates a new Buffer and initializes its internal data to
|
// NewBuffer allocates a new Buffer and initializes its internal data to
|
||||||
|
|
@ -343,6 +375,30 @@ func (p *Buffer) SetBuf(s []byte) {
|
||||||
// Bytes returns the contents of the Buffer.
|
// Bytes returns the contents of the Buffer.
|
||||||
func (p *Buffer) Bytes() []byte { return p.buf }
|
func (p *Buffer) Bytes() []byte { return p.buf }
|
||||||
|
|
||||||
|
// SetDeterministic sets whether to use deterministic serialization.
|
||||||
|
//
|
||||||
|
// Deterministic serialization guarantees that for a given binary, equal
|
||||||
|
// messages will always be serialized to the same bytes. This implies:
|
||||||
|
//
|
||||||
|
// - Repeated serialization of a message will return the same bytes.
|
||||||
|
// - Different processes of the same binary (which may be executing on
|
||||||
|
// different machines) will serialize equal messages to the same bytes.
|
||||||
|
//
|
||||||
|
// Note that the deterministic serialization is NOT canonical across
|
||||||
|
// languages. It is not guaranteed to remain stable over time. It is unstable
|
||||||
|
// across different builds with schema changes due to unknown fields.
|
||||||
|
// Users who need canonical serialization (e.g., persistent storage in a
|
||||||
|
// canonical form, fingerprinting, etc.) should define their own
|
||||||
|
// canonicalization specification and implement their own serializer rather
|
||||||
|
// than relying on this API.
|
||||||
|
//
|
||||||
|
// If deterministic serialization is requested, map entries will be sorted
|
||||||
|
// by keys in lexographical order. This is an implementation detail and
|
||||||
|
// subject to change.
|
||||||
|
func (p *Buffer) SetDeterministic(deterministic bool) {
|
||||||
|
p.deterministic = deterministic
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper routines for simplifying the creation of optional fields of basic type.
|
* Helper routines for simplifying the creation of optional fields of basic type.
|
||||||
*/
|
*/
|
||||||
|
|
@ -831,22 +887,12 @@ func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMes
|
||||||
return sf, false, nil
|
return sf, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mapKeys returns a sort.Interface to be used for sorting the map keys.
|
||||||
// Map fields may have key types of non-float scalars, strings and enums.
|
// Map fields may have key types of non-float scalars, strings and enums.
|
||||||
// The easiest way to sort them in some deterministic order is to use fmt.
|
|
||||||
// If this turns out to be inefficient we can always consider other options,
|
|
||||||
// such as doing a Schwartzian transform.
|
|
||||||
|
|
||||||
func mapKeys(vs []reflect.Value) sort.Interface {
|
func mapKeys(vs []reflect.Value) sort.Interface {
|
||||||
s := mapKeySorter{
|
s := mapKeySorter{vs: vs}
|
||||||
vs: vs,
|
|
||||||
// default Less function: textual comparison
|
|
||||||
less: func(a, b reflect.Value) bool {
|
|
||||||
return fmt.Sprint(a.Interface()) < fmt.Sprint(b.Interface())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps;
|
// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
|
||||||
// numeric keys are sorted numerically.
|
|
||||||
if len(vs) == 0 {
|
if len(vs) == 0 {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
@ -855,6 +901,12 @@ func mapKeys(vs []reflect.Value) sort.Interface {
|
||||||
s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() }
|
s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() }
|
||||||
case reflect.Uint32, reflect.Uint64:
|
case reflect.Uint32, reflect.Uint64:
|
||||||
s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() }
|
s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() }
|
||||||
|
case reflect.Bool:
|
||||||
|
s.less = func(a, b reflect.Value) bool { return !a.Bool() && b.Bool() } // false < true
|
||||||
|
case reflect.String:
|
||||||
|
s.less = func(a, b reflect.Value) bool { return a.String() < b.String() }
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unsupported map key type: %v", vs[0].Kind()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
@ -895,3 +947,13 @@ const ProtoPackageIsVersion2 = true
|
||||||
// ProtoPackageIsVersion1 is referenced from generated protocol buffer files
|
// ProtoPackageIsVersion1 is referenced from generated protocol buffer files
|
||||||
// to assert that that code is compatible with this version of the proto package.
|
// to assert that that code is compatible with this version of the proto package.
|
||||||
const ProtoPackageIsVersion1 = true
|
const ProtoPackageIsVersion1 = true
|
||||||
|
|
||||||
|
// InternalMessageInfo is a type used internally by generated .pb.go files.
|
||||||
|
// This type is not intended to be used by non-generated code.
|
||||||
|
// This type is not subject to any compatibility guarantee.
|
||||||
|
type InternalMessageInfo struct {
|
||||||
|
marshal *marshalInfo
|
||||||
|
unmarshal *unmarshalInfo
|
||||||
|
merge *mergeInfo
|
||||||
|
discard *discardInfo
|
||||||
|
}
|
||||||
|
|
|
||||||
81
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/message_set.go
generated
vendored
81
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/message_set.go
generated
vendored
|
|
@ -42,6 +42,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// errNoMessageTypeID occurs when a protocol buffer does not have a message type ID.
|
// errNoMessageTypeID occurs when a protocol buffer does not have a message type ID.
|
||||||
|
|
@ -94,10 +95,7 @@ func (ms *messageSet) find(pb Message) *_MessageSet_Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *messageSet) Has(pb Message) bool {
|
func (ms *messageSet) Has(pb Message) bool {
|
||||||
if ms.find(pb) != nil {
|
return ms.find(pb) != nil
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *messageSet) Unmarshal(pb Message) error {
|
func (ms *messageSet) Unmarshal(pb Message) error {
|
||||||
|
|
@ -150,46 +148,42 @@ func skipVarint(buf []byte) []byte {
|
||||||
// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
|
// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
|
||||||
// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
|
// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
|
||||||
func MarshalMessageSet(exts interface{}) ([]byte, error) {
|
func MarshalMessageSet(exts interface{}) ([]byte, error) {
|
||||||
var m map[int32]Extension
|
return marshalMessageSet(exts, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// marshaMessageSet implements above function, with the opt to turn on / off deterministic during Marshal.
|
||||||
|
func marshalMessageSet(exts interface{}, deterministic bool) ([]byte, error) {
|
||||||
switch exts := exts.(type) {
|
switch exts := exts.(type) {
|
||||||
case *XXX_InternalExtensions:
|
case *XXX_InternalExtensions:
|
||||||
if err := encodeExtensions(exts); err != nil {
|
var u marshalInfo
|
||||||
return nil, err
|
siz := u.sizeMessageSet(exts)
|
||||||
}
|
b := make([]byte, 0, siz)
|
||||||
m, _ = exts.extensionsRead()
|
return u.appendMessageSet(b, exts, deterministic)
|
||||||
|
|
||||||
case map[int32]Extension:
|
case map[int32]Extension:
|
||||||
if err := encodeExtensionsMap(exts); err != nil {
|
// This is an old-style extension map.
|
||||||
return nil, err
|
// Wrap it in a new-style XXX_InternalExtensions.
|
||||||
|
ie := XXX_InternalExtensions{
|
||||||
|
p: &struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
extensionMap map[int32]Extension
|
||||||
|
}{
|
||||||
|
extensionMap: exts,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
m = exts
|
|
||||||
|
var u marshalInfo
|
||||||
|
siz := u.sizeMessageSet(&ie)
|
||||||
|
b := make([]byte, 0, siz)
|
||||||
|
return u.appendMessageSet(b, &ie, deterministic)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("proto: not an extension map")
|
return nil, errors.New("proto: not an extension map")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort extension IDs to provide a deterministic encoding.
|
|
||||||
// See also enc_map in encode.go.
|
|
||||||
ids := make([]int, 0, len(m))
|
|
||||||
for id := range m {
|
|
||||||
ids = append(ids, int(id))
|
|
||||||
}
|
|
||||||
sort.Ints(ids)
|
|
||||||
|
|
||||||
ms := &messageSet{Item: make([]*_MessageSet_Item, 0, len(m))}
|
|
||||||
for _, id := range ids {
|
|
||||||
e := m[int32(id)]
|
|
||||||
// Remove the wire type and field number varint, as well as the length varint.
|
|
||||||
msg := skipVarint(skipVarint(e.enc))
|
|
||||||
|
|
||||||
ms.Item = append(ms.Item, &_MessageSet_Item{
|
|
||||||
TypeId: Int32(int32(id)),
|
|
||||||
Message: msg,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return Marshal(ms)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
|
// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
|
||||||
// It is called by generated Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
|
// It is called by Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
|
||||||
func UnmarshalMessageSet(buf []byte, exts interface{}) error {
|
func UnmarshalMessageSet(buf []byte, exts interface{}) error {
|
||||||
var m map[int32]Extension
|
var m map[int32]Extension
|
||||||
switch exts := exts.(type) {
|
switch exts := exts.(type) {
|
||||||
|
|
@ -235,7 +229,15 @@ func MarshalMessageSetJSON(exts interface{}) ([]byte, error) {
|
||||||
var m map[int32]Extension
|
var m map[int32]Extension
|
||||||
switch exts := exts.(type) {
|
switch exts := exts.(type) {
|
||||||
case *XXX_InternalExtensions:
|
case *XXX_InternalExtensions:
|
||||||
m, _ = exts.extensionsRead()
|
var mu sync.Locker
|
||||||
|
m, mu = exts.extensionsRead()
|
||||||
|
if m != nil {
|
||||||
|
// Keep the extensions map locked until we're done marshaling to prevent
|
||||||
|
// races between marshaling and unmarshaling the lazily-{en,de}coded
|
||||||
|
// values.
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
}
|
||||||
case map[int32]Extension:
|
case map[int32]Extension:
|
||||||
m = exts
|
m = exts
|
||||||
default:
|
default:
|
||||||
|
|
@ -253,15 +255,16 @@ func MarshalMessageSetJSON(exts interface{}) ([]byte, error) {
|
||||||
|
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
ext := m[id]
|
ext := m[id]
|
||||||
if i > 0 {
|
|
||||||
b.WriteByte(',')
|
|
||||||
}
|
|
||||||
|
|
||||||
msd, ok := messageSetMap[id]
|
msd, ok := messageSetMap[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Unknown type; we can't render it, so skip it.
|
// Unknown type; we can't render it, so skip it.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if i > 0 && b.Len() > 1 {
|
||||||
|
b.WriteByte(',')
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(&b, `"[%s]":`, msd.name)
|
fmt.Fprintf(&b, `"[%s]":`, msd.name)
|
||||||
|
|
||||||
x := ext.value
|
x := ext.value
|
||||||
|
|
|
||||||
637
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/pointer_reflect.go
generated
vendored
637
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/pointer_reflect.go
generated
vendored
|
|
@ -29,7 +29,7 @@
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
// +build appengine js
|
// +build purego appengine js
|
||||||
|
|
||||||
// This file contains an implementation of proto field accesses using package reflect.
|
// This file contains an implementation of proto field accesses using package reflect.
|
||||||
// It is slower than the code in pointer_unsafe.go but it avoids package unsafe and can
|
// It is slower than the code in pointer_unsafe.go but it avoids package unsafe and can
|
||||||
|
|
@ -38,32 +38,13 @@
|
||||||
package proto
|
package proto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A structPointer is a pointer to a struct.
|
const unsafeAllowed = false
|
||||||
type structPointer struct {
|
|
||||||
v reflect.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
// toStructPointer returns a structPointer equivalent to the given reflect value.
|
// A field identifies a field in a struct, accessible from a pointer.
|
||||||
// The reflect value must itself be a pointer to a struct.
|
|
||||||
func toStructPointer(v reflect.Value) structPointer {
|
|
||||||
return structPointer{v}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNil reports whether p is nil.
|
|
||||||
func structPointer_IsNil(p structPointer) bool {
|
|
||||||
return p.v.IsNil()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface returns the struct pointer as an interface value.
|
|
||||||
func structPointer_Interface(p structPointer, _ reflect.Type) interface{} {
|
|
||||||
return p.v.Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
// A field identifies a field in a struct, accessible from a structPointer.
|
|
||||||
// In this implementation, a field is identified by the sequence of field indices
|
// In this implementation, a field is identified by the sequence of field indices
|
||||||
// passed to reflect's FieldByIndex.
|
// passed to reflect's FieldByIndex.
|
||||||
type field []int
|
type field []int
|
||||||
|
|
@ -76,409 +57,301 @@ func toField(f *reflect.StructField) field {
|
||||||
// invalidField is an invalid field identifier.
|
// invalidField is an invalid field identifier.
|
||||||
var invalidField = field(nil)
|
var invalidField = field(nil)
|
||||||
|
|
||||||
|
// zeroField is a noop when calling pointer.offset.
|
||||||
|
var zeroField = field([]int{})
|
||||||
|
|
||||||
// IsValid reports whether the field identifier is valid.
|
// IsValid reports whether the field identifier is valid.
|
||||||
func (f field) IsValid() bool { return f != nil }
|
func (f field) IsValid() bool { return f != nil }
|
||||||
|
|
||||||
// field returns the given field in the struct as a reflect value.
|
// The pointer type is for the table-driven decoder.
|
||||||
func structPointer_field(p structPointer, f field) reflect.Value {
|
// The implementation here uses a reflect.Value of pointer type to
|
||||||
// Special case: an extension map entry with a value of type T
|
// create a generic pointer. In pointer_unsafe.go we use unsafe
|
||||||
// passes a *T to the struct-handling code with a zero field,
|
// instead of reflect to implement the same (but faster) interface.
|
||||||
// expecting that it will be treated as equivalent to *struct{ X T },
|
type pointer struct {
|
||||||
// which has the same memory layout. We have to handle that case
|
|
||||||
// specially, because reflect will panic if we call FieldByIndex on a
|
|
||||||
// non-struct.
|
|
||||||
if f == nil {
|
|
||||||
return p.v.Elem()
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.v.Elem().FieldByIndex(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ifield returns the given field in the struct as an interface value.
|
|
||||||
func structPointer_ifield(p structPointer, f field) interface{} {
|
|
||||||
return structPointer_field(p, f).Addr().Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bytes returns the address of a []byte field in the struct.
|
|
||||||
func structPointer_Bytes(p structPointer, f field) *[]byte {
|
|
||||||
return structPointer_ifield(p, f).(*[]byte)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BytesSlice returns the address of a [][]byte field in the struct.
|
|
||||||
func structPointer_BytesSlice(p structPointer, f field) *[][]byte {
|
|
||||||
return structPointer_ifield(p, f).(*[][]byte)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bool returns the address of a *bool field in the struct.
|
|
||||||
func structPointer_Bool(p structPointer, f field) **bool {
|
|
||||||
return structPointer_ifield(p, f).(**bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BoolVal returns the address of a bool field in the struct.
|
|
||||||
func structPointer_BoolVal(p structPointer, f field) *bool {
|
|
||||||
return structPointer_ifield(p, f).(*bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BoolSlice returns the address of a []bool field in the struct.
|
|
||||||
func structPointer_BoolSlice(p structPointer, f field) *[]bool {
|
|
||||||
return structPointer_ifield(p, f).(*[]bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the address of a *string field in the struct.
|
|
||||||
func structPointer_String(p structPointer, f field) **string {
|
|
||||||
return structPointer_ifield(p, f).(**string)
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringVal returns the address of a string field in the struct.
|
|
||||||
func structPointer_StringVal(p structPointer, f field) *string {
|
|
||||||
return structPointer_ifield(p, f).(*string)
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringSlice returns the address of a []string field in the struct.
|
|
||||||
func structPointer_StringSlice(p structPointer, f field) *[]string {
|
|
||||||
return structPointer_ifield(p, f).(*[]string)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extensions returns the address of an extension map field in the struct.
|
|
||||||
func structPointer_Extensions(p structPointer, f field) *XXX_InternalExtensions {
|
|
||||||
return structPointer_ifield(p, f).(*XXX_InternalExtensions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtMap returns the address of an extension map field in the struct.
|
|
||||||
func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension {
|
|
||||||
return structPointer_ifield(p, f).(*map[int32]Extension)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewAt returns the reflect.Value for a pointer to a field in the struct.
|
|
||||||
func structPointer_NewAt(p structPointer, f field, typ reflect.Type) reflect.Value {
|
|
||||||
return structPointer_field(p, f).Addr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStructPointer writes a *struct field in the struct.
|
|
||||||
func structPointer_SetStructPointer(p structPointer, f field, q structPointer) {
|
|
||||||
structPointer_field(p, f).Set(q.v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStructPointer reads a *struct field in the struct.
|
|
||||||
func structPointer_GetStructPointer(p structPointer, f field) structPointer {
|
|
||||||
return structPointer{structPointer_field(p, f)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// StructPointerSlice the address of a []*struct field in the struct.
|
|
||||||
func structPointer_StructPointerSlice(p structPointer, f field) structPointerSlice {
|
|
||||||
return structPointerSlice{structPointer_field(p, f)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A structPointerSlice represents the address of a slice of pointers to structs
|
|
||||||
// (themselves messages or groups). That is, v.Type() is *[]*struct{...}.
|
|
||||||
type structPointerSlice struct {
|
|
||||||
v reflect.Value
|
v reflect.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p structPointerSlice) Len() int { return p.v.Len() }
|
// toPointer converts an interface of pointer type to a pointer
|
||||||
func (p structPointerSlice) Index(i int) structPointer { return structPointer{p.v.Index(i)} }
|
// that points to the same target.
|
||||||
func (p structPointerSlice) Append(q structPointer) {
|
func toPointer(i *Message) pointer {
|
||||||
p.v.Set(reflect.Append(p.v, q.v))
|
return pointer{v: reflect.ValueOf(*i)}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// toAddrPointer converts an interface to a pointer that points to
|
||||||
int32Type = reflect.TypeOf(int32(0))
|
// the interface data.
|
||||||
uint32Type = reflect.TypeOf(uint32(0))
|
func toAddrPointer(i *interface{}, isptr bool) pointer {
|
||||||
float32Type = reflect.TypeOf(float32(0))
|
v := reflect.ValueOf(*i)
|
||||||
int64Type = reflect.TypeOf(int64(0))
|
u := reflect.New(v.Type())
|
||||||
uint64Type = reflect.TypeOf(uint64(0))
|
u.Elem().Set(v)
|
||||||
float64Type = reflect.TypeOf(float64(0))
|
return pointer{v: u}
|
||||||
)
|
|
||||||
|
|
||||||
// A word32 represents a field of type *int32, *uint32, *float32, or *enum.
|
|
||||||
// That is, v.Type() is *int32, *uint32, *float32, or *enum and v is assignable.
|
|
||||||
type word32 struct {
|
|
||||||
v reflect.Value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNil reports whether p is nil.
|
// valToPointer converts v to a pointer. v must be of pointer type.
|
||||||
func word32_IsNil(p word32) bool {
|
func valToPointer(v reflect.Value) pointer {
|
||||||
|
return pointer{v: v}
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset converts from a pointer to a structure to a pointer to
|
||||||
|
// one of its fields.
|
||||||
|
func (p pointer) offset(f field) pointer {
|
||||||
|
return pointer{v: p.v.Elem().FieldByIndex(f).Addr()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p pointer) isNil() bool {
|
||||||
return p.v.IsNil()
|
return p.v.IsNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sets p to point at a newly allocated word with bits set to x.
|
// grow updates the slice s in place to make it one element longer.
|
||||||
func word32_Set(p word32, o *Buffer, x uint32) {
|
// s must be addressable.
|
||||||
t := p.v.Type().Elem()
|
// Returns the (addressable) new element.
|
||||||
switch t {
|
func grow(s reflect.Value) reflect.Value {
|
||||||
case int32Type:
|
n, m := s.Len(), s.Cap()
|
||||||
if len(o.int32s) == 0 {
|
|
||||||
o.int32s = make([]int32, uint32PoolSize)
|
|
||||||
}
|
|
||||||
o.int32s[0] = int32(x)
|
|
||||||
p.v.Set(reflect.ValueOf(&o.int32s[0]))
|
|
||||||
o.int32s = o.int32s[1:]
|
|
||||||
return
|
|
||||||
case uint32Type:
|
|
||||||
if len(o.uint32s) == 0 {
|
|
||||||
o.uint32s = make([]uint32, uint32PoolSize)
|
|
||||||
}
|
|
||||||
o.uint32s[0] = x
|
|
||||||
p.v.Set(reflect.ValueOf(&o.uint32s[0]))
|
|
||||||
o.uint32s = o.uint32s[1:]
|
|
||||||
return
|
|
||||||
case float32Type:
|
|
||||||
if len(o.float32s) == 0 {
|
|
||||||
o.float32s = make([]float32, uint32PoolSize)
|
|
||||||
}
|
|
||||||
o.float32s[0] = math.Float32frombits(x)
|
|
||||||
p.v.Set(reflect.ValueOf(&o.float32s[0]))
|
|
||||||
o.float32s = o.float32s[1:]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// must be enum
|
|
||||||
p.v.Set(reflect.New(t))
|
|
||||||
p.v.Elem().SetInt(int64(int32(x)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets the bits pointed at by p, as a uint32.
|
|
||||||
func word32_Get(p word32) uint32 {
|
|
||||||
elem := p.v.Elem()
|
|
||||||
switch elem.Kind() {
|
|
||||||
case reflect.Int32:
|
|
||||||
return uint32(elem.Int())
|
|
||||||
case reflect.Uint32:
|
|
||||||
return uint32(elem.Uint())
|
|
||||||
case reflect.Float32:
|
|
||||||
return math.Float32bits(float32(elem.Float()))
|
|
||||||
}
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Word32 returns a reference to a *int32, *uint32, *float32, or *enum field in the struct.
|
|
||||||
func structPointer_Word32(p structPointer, f field) word32 {
|
|
||||||
return word32{structPointer_field(p, f)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A word32Val represents a field of type int32, uint32, float32, or enum.
|
|
||||||
// That is, v.Type() is int32, uint32, float32, or enum and v is assignable.
|
|
||||||
type word32Val struct {
|
|
||||||
v reflect.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set sets *p to x.
|
|
||||||
func word32Val_Set(p word32Val, x uint32) {
|
|
||||||
switch p.v.Type() {
|
|
||||||
case int32Type:
|
|
||||||
p.v.SetInt(int64(x))
|
|
||||||
return
|
|
||||||
case uint32Type:
|
|
||||||
p.v.SetUint(uint64(x))
|
|
||||||
return
|
|
||||||
case float32Type:
|
|
||||||
p.v.SetFloat(float64(math.Float32frombits(x)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// must be enum
|
|
||||||
p.v.SetInt(int64(int32(x)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets the bits pointed at by p, as a uint32.
|
|
||||||
func word32Val_Get(p word32Val) uint32 {
|
|
||||||
elem := p.v
|
|
||||||
switch elem.Kind() {
|
|
||||||
case reflect.Int32:
|
|
||||||
return uint32(elem.Int())
|
|
||||||
case reflect.Uint32:
|
|
||||||
return uint32(elem.Uint())
|
|
||||||
case reflect.Float32:
|
|
||||||
return math.Float32bits(float32(elem.Float()))
|
|
||||||
}
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Word32Val returns a reference to a int32, uint32, float32, or enum field in the struct.
|
|
||||||
func structPointer_Word32Val(p structPointer, f field) word32Val {
|
|
||||||
return word32Val{structPointer_field(p, f)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A word32Slice is a slice of 32-bit values.
|
|
||||||
// That is, v.Type() is []int32, []uint32, []float32, or []enum.
|
|
||||||
type word32Slice struct {
|
|
||||||
v reflect.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p word32Slice) Append(x uint32) {
|
|
||||||
n, m := p.v.Len(), p.v.Cap()
|
|
||||||
if n < m {
|
if n < m {
|
||||||
p.v.SetLen(n + 1)
|
s.SetLen(n + 1)
|
||||||
} else {
|
} else {
|
||||||
t := p.v.Type().Elem()
|
s.Set(reflect.Append(s, reflect.Zero(s.Type().Elem())))
|
||||||
p.v.Set(reflect.Append(p.v, reflect.Zero(t)))
|
|
||||||
}
|
|
||||||
elem := p.v.Index(n)
|
|
||||||
switch elem.Kind() {
|
|
||||||
case reflect.Int32:
|
|
||||||
elem.SetInt(int64(int32(x)))
|
|
||||||
case reflect.Uint32:
|
|
||||||
elem.SetUint(uint64(x))
|
|
||||||
case reflect.Float32:
|
|
||||||
elem.SetFloat(float64(math.Float32frombits(x)))
|
|
||||||
}
|
}
|
||||||
|
return s.Index(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p word32Slice) Len() int {
|
func (p pointer) toInt64() *int64 {
|
||||||
return p.v.Len()
|
return p.v.Interface().(*int64)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt64Ptr() **int64 {
|
||||||
|
return p.v.Interface().(**int64)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt64Slice() *[]int64 {
|
||||||
|
return p.v.Interface().(*[]int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p word32Slice) Index(i int) uint32 {
|
var int32ptr = reflect.TypeOf((*int32)(nil))
|
||||||
elem := p.v.Index(i)
|
|
||||||
switch elem.Kind() {
|
func (p pointer) toInt32() *int32 {
|
||||||
case reflect.Int32:
|
return p.v.Convert(int32ptr).Interface().(*int32)
|
||||||
return uint32(elem.Int())
|
|
||||||
case reflect.Uint32:
|
|
||||||
return uint32(elem.Uint())
|
|
||||||
case reflect.Float32:
|
|
||||||
return math.Float32bits(float32(elem.Float()))
|
|
||||||
}
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Word32Slice returns a reference to a []int32, []uint32, []float32, or []enum field in the struct.
|
// The toInt32Ptr/Slice methods don't work because of enums.
|
||||||
func structPointer_Word32Slice(p structPointer, f field) word32Slice {
|
// Instead, we must use set/get methods for the int32ptr/slice case.
|
||||||
return word32Slice{structPointer_field(p, f)}
|
/*
|
||||||
|
func (p pointer) toInt32Ptr() **int32 {
|
||||||
|
return p.v.Interface().(**int32)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt32Slice() *[]int32 {
|
||||||
|
return p.v.Interface().(*[]int32)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
func (p pointer) getInt32Ptr() *int32 {
|
||||||
|
if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
|
||||||
|
// raw int32 type
|
||||||
|
return p.v.Elem().Interface().(*int32)
|
||||||
|
}
|
||||||
|
// an enum
|
||||||
|
return p.v.Elem().Convert(int32PtrType).Interface().(*int32)
|
||||||
|
}
|
||||||
|
func (p pointer) setInt32Ptr(v int32) {
|
||||||
|
// Allocate value in a *int32. Possibly convert that to a *enum.
|
||||||
|
// Then assign it to a **int32 or **enum.
|
||||||
|
// Note: we can convert *int32 to *enum, but we can't convert
|
||||||
|
// **int32 to **enum!
|
||||||
|
p.v.Elem().Set(reflect.ValueOf(&v).Convert(p.v.Type().Elem()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// word64 is like word32 but for 64-bit values.
|
// getInt32Slice copies []int32 from p as a new slice.
|
||||||
type word64 struct {
|
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||||
v reflect.Value
|
func (p pointer) getInt32Slice() []int32 {
|
||||||
|
if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
|
||||||
|
// raw int32 type
|
||||||
|
return p.v.Elem().Interface().([]int32)
|
||||||
|
}
|
||||||
|
// an enum
|
||||||
|
// Allocate a []int32, then assign []enum's values into it.
|
||||||
|
// Note: we can't convert []enum to []int32.
|
||||||
|
slice := p.v.Elem()
|
||||||
|
s := make([]int32, slice.Len())
|
||||||
|
for i := 0; i < slice.Len(); i++ {
|
||||||
|
s[i] = int32(slice.Index(i).Int())
|
||||||
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func word64_Set(p word64, o *Buffer, x uint64) {
|
// setInt32Slice copies []int32 into p as a new slice.
|
||||||
t := p.v.Type().Elem()
|
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||||
switch t {
|
func (p pointer) setInt32Slice(v []int32) {
|
||||||
case int64Type:
|
if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
|
||||||
if len(o.int64s) == 0 {
|
// raw int32 type
|
||||||
o.int64s = make([]int64, uint64PoolSize)
|
p.v.Elem().Set(reflect.ValueOf(v))
|
||||||
}
|
|
||||||
o.int64s[0] = int64(x)
|
|
||||||
p.v.Set(reflect.ValueOf(&o.int64s[0]))
|
|
||||||
o.int64s = o.int64s[1:]
|
|
||||||
return
|
|
||||||
case uint64Type:
|
|
||||||
if len(o.uint64s) == 0 {
|
|
||||||
o.uint64s = make([]uint64, uint64PoolSize)
|
|
||||||
}
|
|
||||||
o.uint64s[0] = x
|
|
||||||
p.v.Set(reflect.ValueOf(&o.uint64s[0]))
|
|
||||||
o.uint64s = o.uint64s[1:]
|
|
||||||
return
|
|
||||||
case float64Type:
|
|
||||||
if len(o.float64s) == 0 {
|
|
||||||
o.float64s = make([]float64, uint64PoolSize)
|
|
||||||
}
|
|
||||||
o.float64s[0] = math.Float64frombits(x)
|
|
||||||
p.v.Set(reflect.ValueOf(&o.float64s[0]))
|
|
||||||
o.float64s = o.float64s[1:]
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
panic("unreachable")
|
// an enum
|
||||||
}
|
// Allocate a []enum, then assign []int32's values into it.
|
||||||
|
// Note: we can't convert []enum to []int32.
|
||||||
func word64_IsNil(p word64) bool {
|
slice := reflect.MakeSlice(p.v.Type().Elem(), len(v), cap(v))
|
||||||
return p.v.IsNil()
|
for i, x := range v {
|
||||||
}
|
slice.Index(i).SetInt(int64(x))
|
||||||
|
|
||||||
func word64_Get(p word64) uint64 {
|
|
||||||
elem := p.v.Elem()
|
|
||||||
switch elem.Kind() {
|
|
||||||
case reflect.Int64:
|
|
||||||
return uint64(elem.Int())
|
|
||||||
case reflect.Uint64:
|
|
||||||
return elem.Uint()
|
|
||||||
case reflect.Float64:
|
|
||||||
return math.Float64bits(elem.Float())
|
|
||||||
}
|
}
|
||||||
panic("unreachable")
|
p.v.Elem().Set(slice)
|
||||||
|
}
|
||||||
|
func (p pointer) appendInt32Slice(v int32) {
|
||||||
|
grow(p.v.Elem()).SetInt(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func structPointer_Word64(p structPointer, f field) word64 {
|
func (p pointer) toUint64() *uint64 {
|
||||||
return word64{structPointer_field(p, f)}
|
return p.v.Interface().(*uint64)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint64Ptr() **uint64 {
|
||||||
|
return p.v.Interface().(**uint64)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint64Slice() *[]uint64 {
|
||||||
|
return p.v.Interface().(*[]uint64)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint32() *uint32 {
|
||||||
|
return p.v.Interface().(*uint32)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint32Ptr() **uint32 {
|
||||||
|
return p.v.Interface().(**uint32)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint32Slice() *[]uint32 {
|
||||||
|
return p.v.Interface().(*[]uint32)
|
||||||
|
}
|
||||||
|
func (p pointer) toBool() *bool {
|
||||||
|
return p.v.Interface().(*bool)
|
||||||
|
}
|
||||||
|
func (p pointer) toBoolPtr() **bool {
|
||||||
|
return p.v.Interface().(**bool)
|
||||||
|
}
|
||||||
|
func (p pointer) toBoolSlice() *[]bool {
|
||||||
|
return p.v.Interface().(*[]bool)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat64() *float64 {
|
||||||
|
return p.v.Interface().(*float64)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat64Ptr() **float64 {
|
||||||
|
return p.v.Interface().(**float64)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat64Slice() *[]float64 {
|
||||||
|
return p.v.Interface().(*[]float64)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat32() *float32 {
|
||||||
|
return p.v.Interface().(*float32)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat32Ptr() **float32 {
|
||||||
|
return p.v.Interface().(**float32)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat32Slice() *[]float32 {
|
||||||
|
return p.v.Interface().(*[]float32)
|
||||||
|
}
|
||||||
|
func (p pointer) toString() *string {
|
||||||
|
return p.v.Interface().(*string)
|
||||||
|
}
|
||||||
|
func (p pointer) toStringPtr() **string {
|
||||||
|
return p.v.Interface().(**string)
|
||||||
|
}
|
||||||
|
func (p pointer) toStringSlice() *[]string {
|
||||||
|
return p.v.Interface().(*[]string)
|
||||||
|
}
|
||||||
|
func (p pointer) toBytes() *[]byte {
|
||||||
|
return p.v.Interface().(*[]byte)
|
||||||
|
}
|
||||||
|
func (p pointer) toBytesSlice() *[][]byte {
|
||||||
|
return p.v.Interface().(*[][]byte)
|
||||||
|
}
|
||||||
|
func (p pointer) toExtensions() *XXX_InternalExtensions {
|
||||||
|
return p.v.Interface().(*XXX_InternalExtensions)
|
||||||
|
}
|
||||||
|
func (p pointer) toOldExtensions() *map[int32]Extension {
|
||||||
|
return p.v.Interface().(*map[int32]Extension)
|
||||||
|
}
|
||||||
|
func (p pointer) getPointer() pointer {
|
||||||
|
return pointer{v: p.v.Elem()}
|
||||||
|
}
|
||||||
|
func (p pointer) setPointer(q pointer) {
|
||||||
|
p.v.Elem().Set(q.v)
|
||||||
|
}
|
||||||
|
func (p pointer) appendPointer(q pointer) {
|
||||||
|
grow(p.v.Elem()).Set(q.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// word64Val is like word32Val but for 64-bit values.
|
// getPointerSlice copies []*T from p as a new []pointer.
|
||||||
type word64Val struct {
|
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||||
v reflect.Value
|
func (p pointer) getPointerSlice() []pointer {
|
||||||
|
if p.v.IsNil() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
n := p.v.Elem().Len()
|
||||||
|
s := make([]pointer, n)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
s[i] = pointer{v: p.v.Elem().Index(i)}
|
||||||
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func word64Val_Set(p word64Val, o *Buffer, x uint64) {
|
// setPointerSlice copies []pointer into p as a new []*T.
|
||||||
switch p.v.Type() {
|
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||||
case int64Type:
|
func (p pointer) setPointerSlice(v []pointer) {
|
||||||
p.v.SetInt(int64(x))
|
if v == nil {
|
||||||
return
|
p.v.Elem().Set(reflect.New(p.v.Elem().Type()).Elem())
|
||||||
case uint64Type:
|
|
||||||
p.v.SetUint(x)
|
|
||||||
return
|
|
||||||
case float64Type:
|
|
||||||
p.v.SetFloat(math.Float64frombits(x))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
panic("unreachable")
|
s := reflect.MakeSlice(p.v.Elem().Type(), 0, len(v))
|
||||||
}
|
for _, p := range v {
|
||||||
|
s = reflect.Append(s, p.v)
|
||||||
func word64Val_Get(p word64Val) uint64 {
|
|
||||||
elem := p.v
|
|
||||||
switch elem.Kind() {
|
|
||||||
case reflect.Int64:
|
|
||||||
return uint64(elem.Int())
|
|
||||||
case reflect.Uint64:
|
|
||||||
return elem.Uint()
|
|
||||||
case reflect.Float64:
|
|
||||||
return math.Float64bits(elem.Float())
|
|
||||||
}
|
}
|
||||||
panic("unreachable")
|
p.v.Elem().Set(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func structPointer_Word64Val(p structPointer, f field) word64Val {
|
// getInterfacePointer returns a pointer that points to the
|
||||||
return word64Val{structPointer_field(p, f)}
|
// interface data of the interface pointed by p.
|
||||||
}
|
func (p pointer) getInterfacePointer() pointer {
|
||||||
|
if p.v.Elem().IsNil() {
|
||||||
type word64Slice struct {
|
return pointer{v: p.v.Elem()}
|
||||||
v reflect.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p word64Slice) Append(x uint64) {
|
|
||||||
n, m := p.v.Len(), p.v.Cap()
|
|
||||||
if n < m {
|
|
||||||
p.v.SetLen(n + 1)
|
|
||||||
} else {
|
|
||||||
t := p.v.Type().Elem()
|
|
||||||
p.v.Set(reflect.Append(p.v, reflect.Zero(t)))
|
|
||||||
}
|
|
||||||
elem := p.v.Index(n)
|
|
||||||
switch elem.Kind() {
|
|
||||||
case reflect.Int64:
|
|
||||||
elem.SetInt(int64(int64(x)))
|
|
||||||
case reflect.Uint64:
|
|
||||||
elem.SetUint(uint64(x))
|
|
||||||
case reflect.Float64:
|
|
||||||
elem.SetFloat(float64(math.Float64frombits(x)))
|
|
||||||
}
|
}
|
||||||
|
return pointer{v: p.v.Elem().Elem().Elem().Field(0).Addr()} // *interface -> interface -> *struct -> struct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p word64Slice) Len() int {
|
func (p pointer) asPointerTo(t reflect.Type) reflect.Value {
|
||||||
return p.v.Len()
|
// TODO: check that p.v.Type().Elem() == t?
|
||||||
|
return p.v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p word64Slice) Index(i int) uint64 {
|
func atomicLoadUnmarshalInfo(p **unmarshalInfo) *unmarshalInfo {
|
||||||
elem := p.v.Index(i)
|
atomicLock.Lock()
|
||||||
switch elem.Kind() {
|
defer atomicLock.Unlock()
|
||||||
case reflect.Int64:
|
return *p
|
||||||
return uint64(elem.Int())
|
}
|
||||||
case reflect.Uint64:
|
func atomicStoreUnmarshalInfo(p **unmarshalInfo, v *unmarshalInfo) {
|
||||||
return uint64(elem.Uint())
|
atomicLock.Lock()
|
||||||
case reflect.Float64:
|
defer atomicLock.Unlock()
|
||||||
return math.Float64bits(float64(elem.Float()))
|
*p = v
|
||||||
}
|
}
|
||||||
panic("unreachable")
|
func atomicLoadMarshalInfo(p **marshalInfo) *marshalInfo {
|
||||||
|
atomicLock.Lock()
|
||||||
|
defer atomicLock.Unlock()
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
func atomicStoreMarshalInfo(p **marshalInfo, v *marshalInfo) {
|
||||||
|
atomicLock.Lock()
|
||||||
|
defer atomicLock.Unlock()
|
||||||
|
*p = v
|
||||||
|
}
|
||||||
|
func atomicLoadMergeInfo(p **mergeInfo) *mergeInfo {
|
||||||
|
atomicLock.Lock()
|
||||||
|
defer atomicLock.Unlock()
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
func atomicStoreMergeInfo(p **mergeInfo, v *mergeInfo) {
|
||||||
|
atomicLock.Lock()
|
||||||
|
defer atomicLock.Unlock()
|
||||||
|
*p = v
|
||||||
|
}
|
||||||
|
func atomicLoadDiscardInfo(p **discardInfo) *discardInfo {
|
||||||
|
atomicLock.Lock()
|
||||||
|
defer atomicLock.Unlock()
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
func atomicStoreDiscardInfo(p **discardInfo, v *discardInfo) {
|
||||||
|
atomicLock.Lock()
|
||||||
|
defer atomicLock.Unlock()
|
||||||
|
*p = v
|
||||||
}
|
}
|
||||||
|
|
||||||
func structPointer_Word64Slice(p structPointer, f field) word64Slice {
|
var atomicLock sync.Mutex
|
||||||
return word64Slice{structPointer_field(p, f)}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
414
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
generated
vendored
414
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
generated
vendored
|
|
@ -29,7 +29,7 @@
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
// +build !appengine,!js
|
// +build !purego,!appengine,!js
|
||||||
|
|
||||||
// This file contains the implementation of the proto field accesses using package unsafe.
|
// This file contains the implementation of the proto field accesses using package unsafe.
|
||||||
|
|
||||||
|
|
@ -37,38 +37,13 @@ package proto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sync/atomic"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTE: These type_Foo functions would more idiomatically be methods,
|
const unsafeAllowed = true
|
||||||
// but Go does not allow methods on pointer types, and we must preserve
|
|
||||||
// some pointer type for the garbage collector. We use these
|
|
||||||
// funcs with clunky names as our poor approximation to methods.
|
|
||||||
//
|
|
||||||
// An alternative would be
|
|
||||||
// type structPointer struct { p unsafe.Pointer }
|
|
||||||
// but that does not registerize as well.
|
|
||||||
|
|
||||||
// A structPointer is a pointer to a struct.
|
// A field identifies a field in a struct, accessible from a pointer.
|
||||||
type structPointer unsafe.Pointer
|
|
||||||
|
|
||||||
// toStructPointer returns a structPointer equivalent to the given reflect value.
|
|
||||||
func toStructPointer(v reflect.Value) structPointer {
|
|
||||||
return structPointer(unsafe.Pointer(v.Pointer()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNil reports whether p is nil.
|
|
||||||
func structPointer_IsNil(p structPointer) bool {
|
|
||||||
return p == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface returns the struct pointer, assumed to have element type t,
|
|
||||||
// as an interface value.
|
|
||||||
func structPointer_Interface(p structPointer, t reflect.Type) interface{} {
|
|
||||||
return reflect.NewAt(t, unsafe.Pointer(p)).Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
// A field identifies a field in a struct, accessible from a structPointer.
|
|
||||||
// In this implementation, a field is identified by its byte offset from the start of the struct.
|
// In this implementation, a field is identified by its byte offset from the start of the struct.
|
||||||
type field uintptr
|
type field uintptr
|
||||||
|
|
||||||
|
|
@ -80,191 +55,254 @@ func toField(f *reflect.StructField) field {
|
||||||
// invalidField is an invalid field identifier.
|
// invalidField is an invalid field identifier.
|
||||||
const invalidField = ^field(0)
|
const invalidField = ^field(0)
|
||||||
|
|
||||||
|
// zeroField is a noop when calling pointer.offset.
|
||||||
|
const zeroField = field(0)
|
||||||
|
|
||||||
// IsValid reports whether the field identifier is valid.
|
// IsValid reports whether the field identifier is valid.
|
||||||
func (f field) IsValid() bool {
|
func (f field) IsValid() bool {
|
||||||
return f != ^field(0)
|
return f != invalidField
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bytes returns the address of a []byte field in the struct.
|
// The pointer type below is for the new table-driven encoder/decoder.
|
||||||
func structPointer_Bytes(p structPointer, f field) *[]byte {
|
// The implementation here uses unsafe.Pointer to create a generic pointer.
|
||||||
return (*[]byte)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
// In pointer_reflect.go we use reflect instead of unsafe to implement
|
||||||
|
// the same (but slower) interface.
|
||||||
|
type pointer struct {
|
||||||
|
p unsafe.Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
// BytesSlice returns the address of a [][]byte field in the struct.
|
// size of pointer
|
||||||
func structPointer_BytesSlice(p structPointer, f field) *[][]byte {
|
var ptrSize = unsafe.Sizeof(uintptr(0))
|
||||||
return (*[][]byte)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
|
// toPointer converts an interface of pointer type to a pointer
|
||||||
|
// that points to the same target.
|
||||||
|
func toPointer(i *Message) pointer {
|
||||||
|
// Super-tricky - read pointer out of data word of interface value.
|
||||||
|
// Saves ~25ns over the equivalent:
|
||||||
|
// return valToPointer(reflect.ValueOf(*i))
|
||||||
|
return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool returns the address of a *bool field in the struct.
|
// toAddrPointer converts an interface to a pointer that points to
|
||||||
func structPointer_Bool(p structPointer, f field) **bool {
|
// the interface data.
|
||||||
return (**bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
func toAddrPointer(i *interface{}, isptr bool) pointer {
|
||||||
}
|
// Super-tricky - read or get the address of data word of interface value.
|
||||||
|
if isptr {
|
||||||
// BoolVal returns the address of a bool field in the struct.
|
// The interface is of pointer type, thus it is a direct interface.
|
||||||
func structPointer_BoolVal(p structPointer, f field) *bool {
|
// The data word is the pointer data itself. We take its address.
|
||||||
return (*bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
return pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)}
|
||||||
}
|
|
||||||
|
|
||||||
// BoolSlice returns the address of a []bool field in the struct.
|
|
||||||
func structPointer_BoolSlice(p structPointer, f field) *[]bool {
|
|
||||||
return (*[]bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the address of a *string field in the struct.
|
|
||||||
func structPointer_String(p structPointer, f field) **string {
|
|
||||||
return (**string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringVal returns the address of a string field in the struct.
|
|
||||||
func structPointer_StringVal(p structPointer, f field) *string {
|
|
||||||
return (*string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringSlice returns the address of a []string field in the struct.
|
|
||||||
func structPointer_StringSlice(p structPointer, f field) *[]string {
|
|
||||||
return (*[]string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtMap returns the address of an extension map field in the struct.
|
|
||||||
func structPointer_Extensions(p structPointer, f field) *XXX_InternalExtensions {
|
|
||||||
return (*XXX_InternalExtensions)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension {
|
|
||||||
return (*map[int32]Extension)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewAt returns the reflect.Value for a pointer to a field in the struct.
|
|
||||||
func structPointer_NewAt(p structPointer, f field, typ reflect.Type) reflect.Value {
|
|
||||||
return reflect.NewAt(typ, unsafe.Pointer(uintptr(p)+uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStructPointer writes a *struct field in the struct.
|
|
||||||
func structPointer_SetStructPointer(p structPointer, f field, q structPointer) {
|
|
||||||
*(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f))) = q
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStructPointer reads a *struct field in the struct.
|
|
||||||
func structPointer_GetStructPointer(p structPointer, f field) structPointer {
|
|
||||||
return *(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// StructPointerSlice the address of a []*struct field in the struct.
|
|
||||||
func structPointer_StructPointerSlice(p structPointer, f field) *structPointerSlice {
|
|
||||||
return (*structPointerSlice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// A structPointerSlice represents a slice of pointers to structs (themselves submessages or groups).
|
|
||||||
type structPointerSlice []structPointer
|
|
||||||
|
|
||||||
func (v *structPointerSlice) Len() int { return len(*v) }
|
|
||||||
func (v *structPointerSlice) Index(i int) structPointer { return (*v)[i] }
|
|
||||||
func (v *structPointerSlice) Append(p structPointer) { *v = append(*v, p) }
|
|
||||||
|
|
||||||
// A word32 is the address of a "pointer to 32-bit value" field.
|
|
||||||
type word32 **uint32
|
|
||||||
|
|
||||||
// IsNil reports whether *v is nil.
|
|
||||||
func word32_IsNil(p word32) bool {
|
|
||||||
return *p == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set sets *v to point at a newly allocated word set to x.
|
|
||||||
func word32_Set(p word32, o *Buffer, x uint32) {
|
|
||||||
if len(o.uint32s) == 0 {
|
|
||||||
o.uint32s = make([]uint32, uint32PoolSize)
|
|
||||||
}
|
}
|
||||||
o.uint32s[0] = x
|
// The interface is not of pointer type. The data word is the pointer
|
||||||
*p = &o.uint32s[0]
|
// to the data.
|
||||||
o.uint32s = o.uint32s[1:]
|
return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get gets the value pointed at by *v.
|
// valToPointer converts v to a pointer. v must be of pointer type.
|
||||||
func word32_Get(p word32) uint32 {
|
func valToPointer(v reflect.Value) pointer {
|
||||||
return **p
|
return pointer{p: unsafe.Pointer(v.Pointer())}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Word32 returns the address of a *int32, *uint32, *float32, or *enum field in the struct.
|
// offset converts from a pointer to a structure to a pointer to
|
||||||
func structPointer_Word32(p structPointer, f field) word32 {
|
// one of its fields.
|
||||||
return word32((**uint32)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
func (p pointer) offset(f field) pointer {
|
||||||
}
|
// For safety, we should panic if !f.IsValid, however calling panic causes
|
||||||
|
// this to no longer be inlineable, which is a serious performance cost.
|
||||||
// A word32Val is the address of a 32-bit value field.
|
/*
|
||||||
type word32Val *uint32
|
if !f.IsValid() {
|
||||||
|
panic("invalid field")
|
||||||
// Set sets *p to x.
|
|
||||||
func word32Val_Set(p word32Val, x uint32) {
|
|
||||||
*p = x
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets the value pointed at by p.
|
|
||||||
func word32Val_Get(p word32Val) uint32 {
|
|
||||||
return *p
|
|
||||||
}
|
|
||||||
|
|
||||||
// Word32Val returns the address of a *int32, *uint32, *float32, or *enum field in the struct.
|
|
||||||
func structPointer_Word32Val(p structPointer, f field) word32Val {
|
|
||||||
return word32Val((*uint32)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
|
||||||
}
|
|
||||||
|
|
||||||
// A word32Slice is a slice of 32-bit values.
|
|
||||||
type word32Slice []uint32
|
|
||||||
|
|
||||||
func (v *word32Slice) Append(x uint32) { *v = append(*v, x) }
|
|
||||||
func (v *word32Slice) Len() int { return len(*v) }
|
|
||||||
func (v *word32Slice) Index(i int) uint32 { return (*v)[i] }
|
|
||||||
|
|
||||||
// Word32Slice returns the address of a []int32, []uint32, []float32, or []enum field in the struct.
|
|
||||||
func structPointer_Word32Slice(p structPointer, f field) *word32Slice {
|
|
||||||
return (*word32Slice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// word64 is like word32 but for 64-bit values.
|
|
||||||
type word64 **uint64
|
|
||||||
|
|
||||||
func word64_Set(p word64, o *Buffer, x uint64) {
|
|
||||||
if len(o.uint64s) == 0 {
|
|
||||||
o.uint64s = make([]uint64, uint64PoolSize)
|
|
||||||
}
|
}
|
||||||
o.uint64s[0] = x
|
*/
|
||||||
*p = &o.uint64s[0]
|
return pointer{p: unsafe.Pointer(uintptr(p.p) + uintptr(f))}
|
||||||
o.uint64s = o.uint64s[1:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func word64_IsNil(p word64) bool {
|
func (p pointer) isNil() bool {
|
||||||
return *p == nil
|
return p.p == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func word64_Get(p word64) uint64 {
|
func (p pointer) toInt64() *int64 {
|
||||||
return **p
|
return (*int64)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt64Ptr() **int64 {
|
||||||
|
return (**int64)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt64Slice() *[]int64 {
|
||||||
|
return (*[]int64)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt32() *int32 {
|
||||||
|
return (*int32)(p.p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func structPointer_Word64(p structPointer, f field) word64 {
|
// See pointer_reflect.go for why toInt32Ptr/Slice doesn't exist.
|
||||||
return word64((**uint64)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
/*
|
||||||
|
func (p pointer) toInt32Ptr() **int32 {
|
||||||
|
return (**int32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toInt32Slice() *[]int32 {
|
||||||
|
return (*[]int32)(p.p)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
func (p pointer) getInt32Ptr() *int32 {
|
||||||
|
return *(**int32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) setInt32Ptr(v int32) {
|
||||||
|
*(**int32)(p.p) = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
// word64Val is like word32Val but for 64-bit values.
|
// getInt32Slice loads a []int32 from p.
|
||||||
type word64Val *uint64
|
// The value returned is aliased with the original slice.
|
||||||
|
// This behavior differs from the implementation in pointer_reflect.go.
|
||||||
func word64Val_Set(p word64Val, o *Buffer, x uint64) {
|
func (p pointer) getInt32Slice() []int32 {
|
||||||
*p = x
|
return *(*[]int32)(p.p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func word64Val_Get(p word64Val) uint64 {
|
// setInt32Slice stores a []int32 to p.
|
||||||
return *p
|
// The value set is aliased with the input slice.
|
||||||
|
// This behavior differs from the implementation in pointer_reflect.go.
|
||||||
|
func (p pointer) setInt32Slice(v []int32) {
|
||||||
|
*(*[]int32)(p.p) = v
|
||||||
}
|
}
|
||||||
|
|
||||||
func structPointer_Word64Val(p structPointer, f field) word64Val {
|
// TODO: Can we get rid of appendInt32Slice and use setInt32Slice instead?
|
||||||
return word64Val((*uint64)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
func (p pointer) appendInt32Slice(v int32) {
|
||||||
|
s := (*[]int32)(p.p)
|
||||||
|
*s = append(*s, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// word64Slice is like word32Slice but for 64-bit values.
|
func (p pointer) toUint64() *uint64 {
|
||||||
type word64Slice []uint64
|
return (*uint64)(p.p)
|
||||||
|
}
|
||||||
func (v *word64Slice) Append(x uint64) { *v = append(*v, x) }
|
func (p pointer) toUint64Ptr() **uint64 {
|
||||||
func (v *word64Slice) Len() int { return len(*v) }
|
return (**uint64)(p.p)
|
||||||
func (v *word64Slice) Index(i int) uint64 { return (*v)[i] }
|
}
|
||||||
|
func (p pointer) toUint64Slice() *[]uint64 {
|
||||||
func structPointer_Word64Slice(p structPointer, f field) *word64Slice {
|
return (*[]uint64)(p.p)
|
||||||
return (*word64Slice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
}
|
||||||
|
func (p pointer) toUint32() *uint32 {
|
||||||
|
return (*uint32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint32Ptr() **uint32 {
|
||||||
|
return (**uint32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toUint32Slice() *[]uint32 {
|
||||||
|
return (*[]uint32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toBool() *bool {
|
||||||
|
return (*bool)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toBoolPtr() **bool {
|
||||||
|
return (**bool)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toBoolSlice() *[]bool {
|
||||||
|
return (*[]bool)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat64() *float64 {
|
||||||
|
return (*float64)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat64Ptr() **float64 {
|
||||||
|
return (**float64)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat64Slice() *[]float64 {
|
||||||
|
return (*[]float64)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat32() *float32 {
|
||||||
|
return (*float32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat32Ptr() **float32 {
|
||||||
|
return (**float32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toFloat32Slice() *[]float32 {
|
||||||
|
return (*[]float32)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toString() *string {
|
||||||
|
return (*string)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toStringPtr() **string {
|
||||||
|
return (**string)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toStringSlice() *[]string {
|
||||||
|
return (*[]string)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toBytes() *[]byte {
|
||||||
|
return (*[]byte)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toBytesSlice() *[][]byte {
|
||||||
|
return (*[][]byte)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toExtensions() *XXX_InternalExtensions {
|
||||||
|
return (*XXX_InternalExtensions)(p.p)
|
||||||
|
}
|
||||||
|
func (p pointer) toOldExtensions() *map[int32]Extension {
|
||||||
|
return (*map[int32]Extension)(p.p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getPointerSlice loads []*T from p as a []pointer.
|
||||||
|
// The value returned is aliased with the original slice.
|
||||||
|
// This behavior differs from the implementation in pointer_reflect.go.
|
||||||
|
func (p pointer) getPointerSlice() []pointer {
|
||||||
|
// Super-tricky - p should point to a []*T where T is a
|
||||||
|
// message type. We load it as []pointer.
|
||||||
|
return *(*[]pointer)(p.p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setPointerSlice stores []pointer into p as a []*T.
|
||||||
|
// The value set is aliased with the input slice.
|
||||||
|
// This behavior differs from the implementation in pointer_reflect.go.
|
||||||
|
func (p pointer) setPointerSlice(v []pointer) {
|
||||||
|
// Super-tricky - p should point to a []*T where T is a
|
||||||
|
// message type. We store it as []pointer.
|
||||||
|
*(*[]pointer)(p.p) = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// getPointer loads the pointer at p and returns it.
|
||||||
|
func (p pointer) getPointer() pointer {
|
||||||
|
return pointer{p: *(*unsafe.Pointer)(p.p)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setPointer stores the pointer q at p.
|
||||||
|
func (p pointer) setPointer(q pointer) {
|
||||||
|
*(*unsafe.Pointer)(p.p) = q.p
|
||||||
|
}
|
||||||
|
|
||||||
|
// append q to the slice pointed to by p.
|
||||||
|
func (p pointer) appendPointer(q pointer) {
|
||||||
|
s := (*[]unsafe.Pointer)(p.p)
|
||||||
|
*s = append(*s, q.p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getInterfacePointer returns a pointer that points to the
|
||||||
|
// interface data of the interface pointed by p.
|
||||||
|
func (p pointer) getInterfacePointer() pointer {
|
||||||
|
// Super-tricky - read pointer out of data word of interface value.
|
||||||
|
return pointer{p: (*(*[2]unsafe.Pointer)(p.p))[1]}
|
||||||
|
}
|
||||||
|
|
||||||
|
// asPointerTo returns a reflect.Value that is a pointer to an
|
||||||
|
// object of type t stored at p.
|
||||||
|
func (p pointer) asPointerTo(t reflect.Type) reflect.Value {
|
||||||
|
return reflect.NewAt(t, p.p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func atomicLoadUnmarshalInfo(p **unmarshalInfo) *unmarshalInfo {
|
||||||
|
return (*unmarshalInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||||
|
}
|
||||||
|
func atomicStoreUnmarshalInfo(p **unmarshalInfo, v *unmarshalInfo) {
|
||||||
|
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||||
|
}
|
||||||
|
func atomicLoadMarshalInfo(p **marshalInfo) *marshalInfo {
|
||||||
|
return (*marshalInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||||
|
}
|
||||||
|
func atomicStoreMarshalInfo(p **marshalInfo, v *marshalInfo) {
|
||||||
|
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||||
|
}
|
||||||
|
func atomicLoadMergeInfo(p **mergeInfo) *mergeInfo {
|
||||||
|
return (*mergeInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||||
|
}
|
||||||
|
func atomicStoreMergeInfo(p **mergeInfo, v *mergeInfo) {
|
||||||
|
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||||
|
}
|
||||||
|
func atomicLoadDiscardInfo(p **discardInfo) *discardInfo {
|
||||||
|
return (*discardInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||||
|
}
|
||||||
|
func atomicStoreDiscardInfo(p **discardInfo, v *discardInfo) {
|
||||||
|
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
435
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/properties.go
generated
vendored
435
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/properties.go
generated
vendored
|
|
@ -58,42 +58,6 @@ const (
|
||||||
WireFixed32 = 5
|
WireFixed32 = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
const startSize = 10 // initial slice/string sizes
|
|
||||||
|
|
||||||
// Encoders are defined in encode.go
|
|
||||||
// An encoder outputs the full representation of a field, including its
|
|
||||||
// tag and encoder type.
|
|
||||||
type encoder func(p *Buffer, prop *Properties, base structPointer) error
|
|
||||||
|
|
||||||
// A valueEncoder encodes a single integer in a particular encoding.
|
|
||||||
type valueEncoder func(o *Buffer, x uint64) error
|
|
||||||
|
|
||||||
// Sizers are defined in encode.go
|
|
||||||
// A sizer returns the encoded size of a field, including its tag and encoder
|
|
||||||
// type.
|
|
||||||
type sizer func(prop *Properties, base structPointer) int
|
|
||||||
|
|
||||||
// A valueSizer returns the encoded size of a single integer in a particular
|
|
||||||
// encoding.
|
|
||||||
type valueSizer func(x uint64) int
|
|
||||||
|
|
||||||
// Decoders are defined in decode.go
|
|
||||||
// A decoder creates a value from its wire representation.
|
|
||||||
// Unrecognized subelements are saved in unrec.
|
|
||||||
type decoder func(p *Buffer, prop *Properties, base structPointer) error
|
|
||||||
|
|
||||||
// A valueDecoder decodes a single integer in a particular encoding.
|
|
||||||
type valueDecoder func(o *Buffer) (x uint64, err error)
|
|
||||||
|
|
||||||
// A oneofMarshaler does the marshaling for all oneof fields in a message.
|
|
||||||
type oneofMarshaler func(Message, *Buffer) error
|
|
||||||
|
|
||||||
// A oneofUnmarshaler does the unmarshaling for a oneof field in a message.
|
|
||||||
type oneofUnmarshaler func(Message, int, int, *Buffer) (bool, error)
|
|
||||||
|
|
||||||
// A oneofSizer does the sizing for all oneof fields in a message.
|
|
||||||
type oneofSizer func(Message) int
|
|
||||||
|
|
||||||
// tagMap is an optimization over map[int]int for typical protocol buffer
|
// tagMap is an optimization over map[int]int for typical protocol buffer
|
||||||
// use-cases. Encoded protocol buffers are often in tag order with small tag
|
// use-cases. Encoded protocol buffers are often in tag order with small tag
|
||||||
// numbers.
|
// numbers.
|
||||||
|
|
@ -140,13 +104,6 @@ type StructProperties struct {
|
||||||
decoderTags tagMap // map from proto tag to struct field number
|
decoderTags tagMap // map from proto tag to struct field number
|
||||||
decoderOrigNames map[string]int // map from original name to struct field number
|
decoderOrigNames map[string]int // map from original name to struct field number
|
||||||
order []int // list of struct field numbers in tag order
|
order []int // list of struct field numbers in tag order
|
||||||
unrecField field // field id of the XXX_unrecognized []byte field
|
|
||||||
extendable bool // is this an extendable proto
|
|
||||||
|
|
||||||
oneofMarshaler oneofMarshaler
|
|
||||||
oneofUnmarshaler oneofUnmarshaler
|
|
||||||
oneofSizer oneofSizer
|
|
||||||
stype reflect.Type
|
|
||||||
|
|
||||||
// OneofTypes contains information about the oneof fields in this message.
|
// OneofTypes contains information about the oneof fields in this message.
|
||||||
// It is keyed by the original name of a field.
|
// It is keyed by the original name of a field.
|
||||||
|
|
@ -182,41 +139,24 @@ type Properties struct {
|
||||||
Repeated bool
|
Repeated bool
|
||||||
Packed bool // relevant for repeated primitives only
|
Packed bool // relevant for repeated primitives only
|
||||||
Enum string // set for enum types only
|
Enum string // set for enum types only
|
||||||
proto3 bool // whether this is known to be a proto3 field; set for []byte only
|
proto3 bool // whether this is known to be a proto3 field
|
||||||
oneof bool // whether this is a oneof field
|
oneof bool // whether this is a oneof field
|
||||||
|
|
||||||
Default string // default value
|
Default string // default value
|
||||||
HasDefault bool // whether an explicit default was provided
|
HasDefault bool // whether an explicit default was provided
|
||||||
def_uint64 uint64
|
|
||||||
|
|
||||||
enc encoder
|
|
||||||
valEnc valueEncoder // set for bool and numeric types only
|
|
||||||
field field
|
|
||||||
tagcode []byte // encoding of EncodeVarint((Tag<<3)|WireType)
|
|
||||||
tagbuf [8]byte
|
|
||||||
stype reflect.Type // set for struct types only
|
stype reflect.Type // set for struct types only
|
||||||
sprop *StructProperties // set for struct types only
|
sprop *StructProperties // set for struct types only
|
||||||
isMarshaler bool
|
|
||||||
isUnmarshaler bool
|
|
||||||
|
|
||||||
mtype reflect.Type // set for map types only
|
mtype reflect.Type // set for map types only
|
||||||
mkeyprop *Properties // set for map types only
|
MapKeyProp *Properties // set for map types only
|
||||||
mvalprop *Properties // set for map types only
|
MapValProp *Properties // set for map types only
|
||||||
|
|
||||||
size sizer
|
|
||||||
valSize valueSizer // set for bool and numeric types only
|
|
||||||
|
|
||||||
dec decoder
|
|
||||||
valDec valueDecoder // set for bool and numeric types only
|
|
||||||
|
|
||||||
// If this is a packable field, this will be the decoder for the packed version of the field.
|
|
||||||
packedDec decoder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String formats the properties in the protobuf struct field tag style.
|
// String formats the properties in the protobuf struct field tag style.
|
||||||
func (p *Properties) String() string {
|
func (p *Properties) String() string {
|
||||||
s := p.Wire
|
s := p.Wire
|
||||||
s = ","
|
s += ","
|
||||||
s += strconv.Itoa(p.Tag)
|
s += strconv.Itoa(p.Tag)
|
||||||
if p.Required {
|
if p.Required {
|
||||||
s += ",req"
|
s += ",req"
|
||||||
|
|
@ -262,29 +202,14 @@ func (p *Properties) Parse(s string) {
|
||||||
switch p.Wire {
|
switch p.Wire {
|
||||||
case "varint":
|
case "varint":
|
||||||
p.WireType = WireVarint
|
p.WireType = WireVarint
|
||||||
p.valEnc = (*Buffer).EncodeVarint
|
|
||||||
p.valDec = (*Buffer).DecodeVarint
|
|
||||||
p.valSize = sizeVarint
|
|
||||||
case "fixed32":
|
case "fixed32":
|
||||||
p.WireType = WireFixed32
|
p.WireType = WireFixed32
|
||||||
p.valEnc = (*Buffer).EncodeFixed32
|
|
||||||
p.valDec = (*Buffer).DecodeFixed32
|
|
||||||
p.valSize = sizeFixed32
|
|
||||||
case "fixed64":
|
case "fixed64":
|
||||||
p.WireType = WireFixed64
|
p.WireType = WireFixed64
|
||||||
p.valEnc = (*Buffer).EncodeFixed64
|
|
||||||
p.valDec = (*Buffer).DecodeFixed64
|
|
||||||
p.valSize = sizeFixed64
|
|
||||||
case "zigzag32":
|
case "zigzag32":
|
||||||
p.WireType = WireVarint
|
p.WireType = WireVarint
|
||||||
p.valEnc = (*Buffer).EncodeZigzag32
|
|
||||||
p.valDec = (*Buffer).DecodeZigzag32
|
|
||||||
p.valSize = sizeZigzag32
|
|
||||||
case "zigzag64":
|
case "zigzag64":
|
||||||
p.WireType = WireVarint
|
p.WireType = WireVarint
|
||||||
p.valEnc = (*Buffer).EncodeZigzag64
|
|
||||||
p.valDec = (*Buffer).DecodeZigzag64
|
|
||||||
p.valSize = sizeZigzag64
|
|
||||||
case "bytes", "group":
|
case "bytes", "group":
|
||||||
p.WireType = WireBytes
|
p.WireType = WireBytes
|
||||||
// no numeric converter for non-numeric types
|
// no numeric converter for non-numeric types
|
||||||
|
|
@ -299,6 +224,7 @@ func (p *Properties) Parse(s string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outer:
|
||||||
for i := 2; i < len(fields); i++ {
|
for i := 2; i < len(fields); i++ {
|
||||||
f := fields[i]
|
f := fields[i]
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -326,256 +252,41 @@ func (p *Properties) Parse(s string) {
|
||||||
if i+1 < len(fields) {
|
if i+1 < len(fields) {
|
||||||
// Commas aren't escaped, and def is always last.
|
// Commas aren't escaped, and def is always last.
|
||||||
p.Default += "," + strings.Join(fields[i+1:], ",")
|
p.Default += "," + strings.Join(fields[i+1:], ",")
|
||||||
break
|
break outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func logNoSliceEnc(t1, t2 reflect.Type) {
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: no slice oenc for %T = []%T\n", t1, t2)
|
|
||||||
}
|
|
||||||
|
|
||||||
var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
|
var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
|
||||||
|
|
||||||
// Initialize the fields for encoding and decoding.
|
// setFieldProps initializes the field properties for submessages and maps.
|
||||||
func (p *Properties) setEncAndDec(typ reflect.Type, f *reflect.StructField, lockGetProp bool) {
|
func (p *Properties) setFieldProps(typ reflect.Type, f *reflect.StructField, lockGetProp bool) {
|
||||||
p.enc = nil
|
|
||||||
p.dec = nil
|
|
||||||
p.size = nil
|
|
||||||
|
|
||||||
switch t1 := typ; t1.Kind() {
|
switch t1 := typ; t1.Kind() {
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: no coders for %v\n", t1)
|
|
||||||
|
|
||||||
// proto3 scalar types
|
|
||||||
|
|
||||||
case reflect.Bool:
|
|
||||||
p.enc = (*Buffer).enc_proto3_bool
|
|
||||||
p.dec = (*Buffer).dec_proto3_bool
|
|
||||||
p.size = size_proto3_bool
|
|
||||||
case reflect.Int32:
|
|
||||||
p.enc = (*Buffer).enc_proto3_int32
|
|
||||||
p.dec = (*Buffer).dec_proto3_int32
|
|
||||||
p.size = size_proto3_int32
|
|
||||||
case reflect.Uint32:
|
|
||||||
p.enc = (*Buffer).enc_proto3_uint32
|
|
||||||
p.dec = (*Buffer).dec_proto3_int32 // can reuse
|
|
||||||
p.size = size_proto3_uint32
|
|
||||||
case reflect.Int64, reflect.Uint64:
|
|
||||||
p.enc = (*Buffer).enc_proto3_int64
|
|
||||||
p.dec = (*Buffer).dec_proto3_int64
|
|
||||||
p.size = size_proto3_int64
|
|
||||||
case reflect.Float32:
|
|
||||||
p.enc = (*Buffer).enc_proto3_uint32 // can just treat them as bits
|
|
||||||
p.dec = (*Buffer).dec_proto3_int32
|
|
||||||
p.size = size_proto3_uint32
|
|
||||||
case reflect.Float64:
|
|
||||||
p.enc = (*Buffer).enc_proto3_int64 // can just treat them as bits
|
|
||||||
p.dec = (*Buffer).dec_proto3_int64
|
|
||||||
p.size = size_proto3_int64
|
|
||||||
case reflect.String:
|
|
||||||
p.enc = (*Buffer).enc_proto3_string
|
|
||||||
p.dec = (*Buffer).dec_proto3_string
|
|
||||||
p.size = size_proto3_string
|
|
||||||
|
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
switch t2 := t1.Elem(); t2.Kind() {
|
if t1.Elem().Kind() == reflect.Struct {
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: no encoder function for %v -> %v\n", t1, t2)
|
|
||||||
break
|
|
||||||
case reflect.Bool:
|
|
||||||
p.enc = (*Buffer).enc_bool
|
|
||||||
p.dec = (*Buffer).dec_bool
|
|
||||||
p.size = size_bool
|
|
||||||
case reflect.Int32:
|
|
||||||
p.enc = (*Buffer).enc_int32
|
|
||||||
p.dec = (*Buffer).dec_int32
|
|
||||||
p.size = size_int32
|
|
||||||
case reflect.Uint32:
|
|
||||||
p.enc = (*Buffer).enc_uint32
|
|
||||||
p.dec = (*Buffer).dec_int32 // can reuse
|
|
||||||
p.size = size_uint32
|
|
||||||
case reflect.Int64, reflect.Uint64:
|
|
||||||
p.enc = (*Buffer).enc_int64
|
|
||||||
p.dec = (*Buffer).dec_int64
|
|
||||||
p.size = size_int64
|
|
||||||
case reflect.Float32:
|
|
||||||
p.enc = (*Buffer).enc_uint32 // can just treat them as bits
|
|
||||||
p.dec = (*Buffer).dec_int32
|
|
||||||
p.size = size_uint32
|
|
||||||
case reflect.Float64:
|
|
||||||
p.enc = (*Buffer).enc_int64 // can just treat them as bits
|
|
||||||
p.dec = (*Buffer).dec_int64
|
|
||||||
p.size = size_int64
|
|
||||||
case reflect.String:
|
|
||||||
p.enc = (*Buffer).enc_string
|
|
||||||
p.dec = (*Buffer).dec_string
|
|
||||||
p.size = size_string
|
|
||||||
case reflect.Struct:
|
|
||||||
p.stype = t1.Elem()
|
p.stype = t1.Elem()
|
||||||
p.isMarshaler = isMarshaler(t1)
|
|
||||||
p.isUnmarshaler = isUnmarshaler(t1)
|
|
||||||
if p.Wire == "bytes" {
|
|
||||||
p.enc = (*Buffer).enc_struct_message
|
|
||||||
p.dec = (*Buffer).dec_struct_message
|
|
||||||
p.size = size_struct_message
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_struct_group
|
|
||||||
p.dec = (*Buffer).dec_struct_group
|
|
||||||
p.size = size_struct_group
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
switch t2 := t1.Elem(); t2.Kind() {
|
if t2 := t1.Elem(); t2.Kind() == reflect.Ptr && t2.Elem().Kind() == reflect.Struct {
|
||||||
default:
|
|
||||||
logNoSliceEnc(t1, t2)
|
|
||||||
break
|
|
||||||
case reflect.Bool:
|
|
||||||
if p.Packed {
|
|
||||||
p.enc = (*Buffer).enc_slice_packed_bool
|
|
||||||
p.size = size_slice_packed_bool
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_bool
|
|
||||||
p.size = size_slice_bool
|
|
||||||
}
|
|
||||||
p.dec = (*Buffer).dec_slice_bool
|
|
||||||
p.packedDec = (*Buffer).dec_slice_packed_bool
|
|
||||||
case reflect.Int32:
|
|
||||||
if p.Packed {
|
|
||||||
p.enc = (*Buffer).enc_slice_packed_int32
|
|
||||||
p.size = size_slice_packed_int32
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_int32
|
|
||||||
p.size = size_slice_int32
|
|
||||||
}
|
|
||||||
p.dec = (*Buffer).dec_slice_int32
|
|
||||||
p.packedDec = (*Buffer).dec_slice_packed_int32
|
|
||||||
case reflect.Uint32:
|
|
||||||
if p.Packed {
|
|
||||||
p.enc = (*Buffer).enc_slice_packed_uint32
|
|
||||||
p.size = size_slice_packed_uint32
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_uint32
|
|
||||||
p.size = size_slice_uint32
|
|
||||||
}
|
|
||||||
p.dec = (*Buffer).dec_slice_int32
|
|
||||||
p.packedDec = (*Buffer).dec_slice_packed_int32
|
|
||||||
case reflect.Int64, reflect.Uint64:
|
|
||||||
if p.Packed {
|
|
||||||
p.enc = (*Buffer).enc_slice_packed_int64
|
|
||||||
p.size = size_slice_packed_int64
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_int64
|
|
||||||
p.size = size_slice_int64
|
|
||||||
}
|
|
||||||
p.dec = (*Buffer).dec_slice_int64
|
|
||||||
p.packedDec = (*Buffer).dec_slice_packed_int64
|
|
||||||
case reflect.Uint8:
|
|
||||||
p.dec = (*Buffer).dec_slice_byte
|
|
||||||
if p.proto3 {
|
|
||||||
p.enc = (*Buffer).enc_proto3_slice_byte
|
|
||||||
p.size = size_proto3_slice_byte
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_byte
|
|
||||||
p.size = size_slice_byte
|
|
||||||
}
|
|
||||||
case reflect.Float32, reflect.Float64:
|
|
||||||
switch t2.Bits() {
|
|
||||||
case 32:
|
|
||||||
// can just treat them as bits
|
|
||||||
if p.Packed {
|
|
||||||
p.enc = (*Buffer).enc_slice_packed_uint32
|
|
||||||
p.size = size_slice_packed_uint32
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_uint32
|
|
||||||
p.size = size_slice_uint32
|
|
||||||
}
|
|
||||||
p.dec = (*Buffer).dec_slice_int32
|
|
||||||
p.packedDec = (*Buffer).dec_slice_packed_int32
|
|
||||||
case 64:
|
|
||||||
// can just treat them as bits
|
|
||||||
if p.Packed {
|
|
||||||
p.enc = (*Buffer).enc_slice_packed_int64
|
|
||||||
p.size = size_slice_packed_int64
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_int64
|
|
||||||
p.size = size_slice_int64
|
|
||||||
}
|
|
||||||
p.dec = (*Buffer).dec_slice_int64
|
|
||||||
p.packedDec = (*Buffer).dec_slice_packed_int64
|
|
||||||
default:
|
|
||||||
logNoSliceEnc(t1, t2)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case reflect.String:
|
|
||||||
p.enc = (*Buffer).enc_slice_string
|
|
||||||
p.dec = (*Buffer).dec_slice_string
|
|
||||||
p.size = size_slice_string
|
|
||||||
case reflect.Ptr:
|
|
||||||
switch t3 := t2.Elem(); t3.Kind() {
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T -> %T\n", t1, t2, t3)
|
|
||||||
break
|
|
||||||
case reflect.Struct:
|
|
||||||
p.stype = t2.Elem()
|
p.stype = t2.Elem()
|
||||||
p.isMarshaler = isMarshaler(t2)
|
|
||||||
p.isUnmarshaler = isUnmarshaler(t2)
|
|
||||||
if p.Wire == "bytes" {
|
|
||||||
p.enc = (*Buffer).enc_slice_struct_message
|
|
||||||
p.dec = (*Buffer).dec_slice_struct_message
|
|
||||||
p.size = size_slice_struct_message
|
|
||||||
} else {
|
|
||||||
p.enc = (*Buffer).enc_slice_struct_group
|
|
||||||
p.dec = (*Buffer).dec_slice_struct_group
|
|
||||||
p.size = size_slice_struct_group
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case reflect.Slice:
|
|
||||||
switch t2.Elem().Kind() {
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: no slice elem oenc for %T -> %T -> %T\n", t1, t2, t2.Elem())
|
|
||||||
break
|
|
||||||
case reflect.Uint8:
|
|
||||||
p.enc = (*Buffer).enc_slice_slice_byte
|
|
||||||
p.dec = (*Buffer).dec_slice_slice_byte
|
|
||||||
p.size = size_slice_slice_byte
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
p.enc = (*Buffer).enc_new_map
|
|
||||||
p.dec = (*Buffer).dec_new_map
|
|
||||||
p.size = size_new_map
|
|
||||||
|
|
||||||
p.mtype = t1
|
p.mtype = t1
|
||||||
p.mkeyprop = &Properties{}
|
p.MapKeyProp = &Properties{}
|
||||||
p.mkeyprop.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp)
|
p.MapKeyProp.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp)
|
||||||
p.mvalprop = &Properties{}
|
p.MapValProp = &Properties{}
|
||||||
vtype := p.mtype.Elem()
|
vtype := p.mtype.Elem()
|
||||||
if vtype.Kind() != reflect.Ptr && vtype.Kind() != reflect.Slice {
|
if vtype.Kind() != reflect.Ptr && vtype.Kind() != reflect.Slice {
|
||||||
// The value type is not a message (*T) or bytes ([]byte),
|
// The value type is not a message (*T) or bytes ([]byte),
|
||||||
// so we need encoders for the pointer to this type.
|
// so we need encoders for the pointer to this type.
|
||||||
vtype = reflect.PtrTo(vtype)
|
vtype = reflect.PtrTo(vtype)
|
||||||
}
|
}
|
||||||
p.mvalprop.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp)
|
p.MapValProp.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// precalculate tag code
|
|
||||||
wire := p.WireType
|
|
||||||
if p.Packed {
|
|
||||||
wire = WireBytes
|
|
||||||
}
|
|
||||||
x := uint32(p.Tag)<<3 | uint32(wire)
|
|
||||||
i := 0
|
|
||||||
for i = 0; x > 127; i++ {
|
|
||||||
p.tagbuf[i] = 0x80 | uint8(x&0x7F)
|
|
||||||
x >>= 7
|
|
||||||
}
|
|
||||||
p.tagbuf[i] = uint8(x)
|
|
||||||
p.tagcode = p.tagbuf[0 : i+1]
|
|
||||||
|
|
||||||
if p.stype != nil {
|
if p.stype != nil {
|
||||||
if lockGetProp {
|
if lockGetProp {
|
||||||
p.sprop = GetProperties(p.stype)
|
p.sprop = GetProperties(p.stype)
|
||||||
|
|
@ -587,31 +298,8 @@ func (p *Properties) setEncAndDec(typ reflect.Type, f *reflect.StructField, lock
|
||||||
|
|
||||||
var (
|
var (
|
||||||
marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
|
marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
|
||||||
unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// isMarshaler reports whether type t implements Marshaler.
|
|
||||||
func isMarshaler(t reflect.Type) bool {
|
|
||||||
// We're checking for (likely) pointer-receiver methods
|
|
||||||
// so if t is not a pointer, something is very wrong.
|
|
||||||
// The calls above only invoke isMarshaler on pointer types.
|
|
||||||
if t.Kind() != reflect.Ptr {
|
|
||||||
panic("proto: misuse of isMarshaler")
|
|
||||||
}
|
|
||||||
return t.Implements(marshalerType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// isUnmarshaler reports whether type t implements Unmarshaler.
|
|
||||||
func isUnmarshaler(t reflect.Type) bool {
|
|
||||||
// We're checking for (likely) pointer-receiver methods
|
|
||||||
// so if t is not a pointer, something is very wrong.
|
|
||||||
// The calls above only invoke isUnmarshaler on pointer types.
|
|
||||||
if t.Kind() != reflect.Ptr {
|
|
||||||
panic("proto: misuse of isUnmarshaler")
|
|
||||||
}
|
|
||||||
return t.Implements(unmarshalerType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init populates the properties from a protocol buffer struct tag.
|
// Init populates the properties from a protocol buffer struct tag.
|
||||||
func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
|
func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
|
||||||
p.init(typ, name, tag, f, true)
|
p.init(typ, name, tag, f, true)
|
||||||
|
|
@ -621,14 +309,11 @@ func (p *Properties) init(typ reflect.Type, name, tag string, f *reflect.StructF
|
||||||
// "bytes,49,opt,def=hello!"
|
// "bytes,49,opt,def=hello!"
|
||||||
p.Name = name
|
p.Name = name
|
||||||
p.OrigName = name
|
p.OrigName = name
|
||||||
if f != nil {
|
|
||||||
p.field = toField(f)
|
|
||||||
}
|
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.Parse(tag)
|
p.Parse(tag)
|
||||||
p.setEncAndDec(typ, f, lockGetProp)
|
p.setFieldProps(typ, f, lockGetProp)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -649,9 +334,6 @@ func GetProperties(t reflect.Type) *StructProperties {
|
||||||
sprop, ok := propertiesMap[t]
|
sprop, ok := propertiesMap[t]
|
||||||
propertiesMu.RUnlock()
|
propertiesMu.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
if collectStats {
|
|
||||||
stats.Chit++
|
|
||||||
}
|
|
||||||
return sprop
|
return sprop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -664,23 +346,14 @@ func GetProperties(t reflect.Type) *StructProperties {
|
||||||
// getPropertiesLocked requires that propertiesMu is held.
|
// getPropertiesLocked requires that propertiesMu is held.
|
||||||
func getPropertiesLocked(t reflect.Type) *StructProperties {
|
func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||||
if prop, ok := propertiesMap[t]; ok {
|
if prop, ok := propertiesMap[t]; ok {
|
||||||
if collectStats {
|
|
||||||
stats.Chit++
|
|
||||||
}
|
|
||||||
return prop
|
return prop
|
||||||
}
|
}
|
||||||
if collectStats {
|
|
||||||
stats.Cmiss++
|
|
||||||
}
|
|
||||||
|
|
||||||
prop := new(StructProperties)
|
prop := new(StructProperties)
|
||||||
// in case of recursive protos, fill this in now.
|
// in case of recursive protos, fill this in now.
|
||||||
propertiesMap[t] = prop
|
propertiesMap[t] = prop
|
||||||
|
|
||||||
// build properties
|
// build properties
|
||||||
prop.extendable = reflect.PtrTo(t).Implements(extendableProtoType) ||
|
|
||||||
reflect.PtrTo(t).Implements(extendableProtoV1Type)
|
|
||||||
prop.unrecField = invalidField
|
|
||||||
prop.Prop = make([]*Properties, t.NumField())
|
prop.Prop = make([]*Properties, t.NumField())
|
||||||
prop.order = make([]int, t.NumField())
|
prop.order = make([]int, t.NumField())
|
||||||
|
|
||||||
|
|
@ -690,17 +363,6 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||||
name := f.Name
|
name := f.Name
|
||||||
p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
|
p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
|
||||||
|
|
||||||
if f.Name == "XXX_InternalExtensions" { // special case
|
|
||||||
p.enc = (*Buffer).enc_exts
|
|
||||||
p.dec = nil // not needed
|
|
||||||
p.size = size_exts
|
|
||||||
} else if f.Name == "XXX_extensions" { // special case
|
|
||||||
p.enc = (*Buffer).enc_map
|
|
||||||
p.dec = nil // not needed
|
|
||||||
p.size = size_map
|
|
||||||
} else if f.Name == "XXX_unrecognized" { // special case
|
|
||||||
prop.unrecField = toField(&f)
|
|
||||||
}
|
|
||||||
oneof := f.Tag.Get("protobuf_oneof") // special case
|
oneof := f.Tag.Get("protobuf_oneof") // special case
|
||||||
if oneof != "" {
|
if oneof != "" {
|
||||||
// Oneof fields don't use the traditional protobuf tag.
|
// Oneof fields don't use the traditional protobuf tag.
|
||||||
|
|
@ -715,9 +377,6 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||||
}
|
}
|
||||||
print("\n")
|
print("\n")
|
||||||
}
|
}
|
||||||
if p.enc == nil && !strings.HasPrefix(f.Name, "XXX_") && oneof == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "proto: no encoder for", f.Name, f.Type.String(), "[GetProperties]")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-order prop.order.
|
// Re-order prop.order.
|
||||||
|
|
@ -728,8 +387,7 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||||
}
|
}
|
||||||
if om, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
|
if om, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
|
||||||
var oots []interface{}
|
var oots []interface{}
|
||||||
prop.oneofMarshaler, prop.oneofUnmarshaler, prop.oneofSizer, oots = om.XXX_OneofFuncs()
|
_, _, _, oots = om.XXX_OneofFuncs()
|
||||||
prop.stype = t
|
|
||||||
|
|
||||||
// Interpret oneof metadata.
|
// Interpret oneof metadata.
|
||||||
prop.OneofTypes = make(map[string]*OneofProperties)
|
prop.OneofTypes = make(map[string]*OneofProperties)
|
||||||
|
|
@ -779,30 +437,6 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||||
return prop
|
return prop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the Properties object for the x[0]'th field of the structure.
|
|
||||||
func propByIndex(t reflect.Type, x []int) *Properties {
|
|
||||||
if len(x) != 1 {
|
|
||||||
fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
prop := GetProperties(t)
|
|
||||||
return prop.Prop[x[0]]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the address and type of a pointer to a struct from an interface.
|
|
||||||
func getbase(pb Message) (t reflect.Type, b structPointer, err error) {
|
|
||||||
if pb == nil {
|
|
||||||
err = ErrNil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// get the reflect type of the pointer to the struct.
|
|
||||||
t = reflect.TypeOf(pb)
|
|
||||||
// get the address of the struct.
|
|
||||||
value := reflect.ValueOf(pb)
|
|
||||||
b = toStructPointer(value)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// A global registry of enum types.
|
// A global registry of enum types.
|
||||||
// The generated code will register the generated maps by calling RegisterEnum.
|
// The generated code will register the generated maps by calling RegisterEnum.
|
||||||
|
|
||||||
|
|
@ -826,20 +460,42 @@ func EnumValueMap(enumType string) map[string]int32 {
|
||||||
// A registry of all linked message types.
|
// A registry of all linked message types.
|
||||||
// The string is a fully-qualified proto name ("pkg.Message").
|
// The string is a fully-qualified proto name ("pkg.Message").
|
||||||
var (
|
var (
|
||||||
protoTypes = make(map[string]reflect.Type)
|
protoTypedNils = make(map[string]Message) // a map from proto names to typed nil pointers
|
||||||
|
protoMapTypes = make(map[string]reflect.Type) // a map from proto names to map types
|
||||||
revProtoTypes = make(map[reflect.Type]string)
|
revProtoTypes = make(map[reflect.Type]string)
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterType is called from generated code and maps from the fully qualified
|
// RegisterType is called from generated code and maps from the fully qualified
|
||||||
// proto name to the type (pointer to struct) of the protocol buffer.
|
// proto name to the type (pointer to struct) of the protocol buffer.
|
||||||
func RegisterType(x Message, name string) {
|
func RegisterType(x Message, name string) {
|
||||||
if _, ok := protoTypes[name]; ok {
|
if _, ok := protoTypedNils[name]; ok {
|
||||||
// TODO: Some day, make this a panic.
|
// TODO: Some day, make this a panic.
|
||||||
log.Printf("proto: duplicate proto type registered: %s", name)
|
log.Printf("proto: duplicate proto type registered: %s", name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t := reflect.TypeOf(x)
|
t := reflect.TypeOf(x)
|
||||||
protoTypes[name] = t
|
if v := reflect.ValueOf(x); v.Kind() == reflect.Ptr && v.Pointer() == 0 {
|
||||||
|
// Generated code always calls RegisterType with nil x.
|
||||||
|
// This check is just for extra safety.
|
||||||
|
protoTypedNils[name] = x
|
||||||
|
} else {
|
||||||
|
protoTypedNils[name] = reflect.Zero(t).Interface().(Message)
|
||||||
|
}
|
||||||
|
revProtoTypes[t] = name
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterMapType is called from generated code and maps from the fully qualified
|
||||||
|
// proto name to the native map type of the proto map definition.
|
||||||
|
func RegisterMapType(x interface{}, name string) {
|
||||||
|
if reflect.TypeOf(x).Kind() != reflect.Map {
|
||||||
|
panic(fmt.Sprintf("RegisterMapType(%T, %q); want map", x, name))
|
||||||
|
}
|
||||||
|
if _, ok := protoMapTypes[name]; ok {
|
||||||
|
log.Printf("proto: duplicate proto type registered: %s", name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := reflect.TypeOf(x)
|
||||||
|
protoMapTypes[name] = t
|
||||||
revProtoTypes[t] = name
|
revProtoTypes[t] = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -855,7 +511,14 @@ func MessageName(x Message) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageType returns the message type (pointer to struct) for a named message.
|
// MessageType returns the message type (pointer to struct) for a named message.
|
||||||
func MessageType(name string) reflect.Type { return protoTypes[name] }
|
// The type is not guaranteed to implement proto.Message if the name refers to a
|
||||||
|
// map entry.
|
||||||
|
func MessageType(name string) reflect.Type {
|
||||||
|
if t, ok := protoTypedNils[name]; ok {
|
||||||
|
return reflect.TypeOf(t)
|
||||||
|
}
|
||||||
|
return protoMapTypes[name]
|
||||||
|
}
|
||||||
|
|
||||||
// A registry of all linked proto files.
|
// A registry of all linked proto files.
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
2767
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/table_marshal.go
generated
vendored
Normal file
2767
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/table_marshal.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
654
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/table_merge.go
generated
vendored
Normal file
654
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/table_merge.go
generated
vendored
Normal file
|
|
@ -0,0 +1,654 @@
|
||||||
|
// Go support for Protocol Buffers - Google's data interchange format
|
||||||
|
//
|
||||||
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
|
// https://github.com/golang/protobuf
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following disclaimer
|
||||||
|
// in the documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
// * Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
package proto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Merge merges the src message into dst.
|
||||||
|
// This assumes that dst and src of the same type and are non-nil.
|
||||||
|
func (a *InternalMessageInfo) Merge(dst, src Message) {
|
||||||
|
mi := atomicLoadMergeInfo(&a.merge)
|
||||||
|
if mi == nil {
|
||||||
|
mi = getMergeInfo(reflect.TypeOf(dst).Elem())
|
||||||
|
atomicStoreMergeInfo(&a.merge, mi)
|
||||||
|
}
|
||||||
|
mi.merge(toPointer(&dst), toPointer(&src))
|
||||||
|
}
|
||||||
|
|
||||||
|
type mergeInfo struct {
|
||||||
|
typ reflect.Type
|
||||||
|
|
||||||
|
initialized int32 // 0: only typ is valid, 1: everything is valid
|
||||||
|
lock sync.Mutex
|
||||||
|
|
||||||
|
fields []mergeFieldInfo
|
||||||
|
unrecognized field // Offset of XXX_unrecognized
|
||||||
|
}
|
||||||
|
|
||||||
|
type mergeFieldInfo struct {
|
||||||
|
field field // Offset of field, guaranteed to be valid
|
||||||
|
|
||||||
|
// isPointer reports whether the value in the field is a pointer.
|
||||||
|
// This is true for the following situations:
|
||||||
|
// * Pointer to struct
|
||||||
|
// * Pointer to basic type (proto2 only)
|
||||||
|
// * Slice (first value in slice header is a pointer)
|
||||||
|
// * String (first value in string header is a pointer)
|
||||||
|
isPointer bool
|
||||||
|
|
||||||
|
// basicWidth reports the width of the field assuming that it is directly
|
||||||
|
// embedded in the struct (as is the case for basic types in proto3).
|
||||||
|
// The possible values are:
|
||||||
|
// 0: invalid
|
||||||
|
// 1: bool
|
||||||
|
// 4: int32, uint32, float32
|
||||||
|
// 8: int64, uint64, float64
|
||||||
|
basicWidth int
|
||||||
|
|
||||||
|
// Where dst and src are pointers to the types being merged.
|
||||||
|
merge func(dst, src pointer)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
mergeInfoMap = map[reflect.Type]*mergeInfo{}
|
||||||
|
mergeInfoLock sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
|
func getMergeInfo(t reflect.Type) *mergeInfo {
|
||||||
|
mergeInfoLock.Lock()
|
||||||
|
defer mergeInfoLock.Unlock()
|
||||||
|
mi := mergeInfoMap[t]
|
||||||
|
if mi == nil {
|
||||||
|
mi = &mergeInfo{typ: t}
|
||||||
|
mergeInfoMap[t] = mi
|
||||||
|
}
|
||||||
|
return mi
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge merges src into dst assuming they are both of type *mi.typ.
|
||||||
|
func (mi *mergeInfo) merge(dst, src pointer) {
|
||||||
|
if dst.isNil() {
|
||||||
|
panic("proto: nil destination")
|
||||||
|
}
|
||||||
|
if src.isNil() {
|
||||||
|
return // Nothing to do.
|
||||||
|
}
|
||||||
|
|
||||||
|
if atomic.LoadInt32(&mi.initialized) == 0 {
|
||||||
|
mi.computeMergeInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fi := range mi.fields {
|
||||||
|
sfp := src.offset(fi.field)
|
||||||
|
|
||||||
|
// As an optimization, we can avoid the merge function call cost
|
||||||
|
// if we know for sure that the source will have no effect
|
||||||
|
// by checking if it is the zero value.
|
||||||
|
if unsafeAllowed {
|
||||||
|
if fi.isPointer && sfp.getPointer().isNil() { // Could be slice or string
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if fi.basicWidth > 0 {
|
||||||
|
switch {
|
||||||
|
case fi.basicWidth == 1 && !*sfp.toBool():
|
||||||
|
continue
|
||||||
|
case fi.basicWidth == 4 && *sfp.toUint32() == 0:
|
||||||
|
continue
|
||||||
|
case fi.basicWidth == 8 && *sfp.toUint64() == 0:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dfp := dst.offset(fi.field)
|
||||||
|
fi.merge(dfp, sfp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Make this faster?
|
||||||
|
out := dst.asPointerTo(mi.typ).Elem()
|
||||||
|
in := src.asPointerTo(mi.typ).Elem()
|
||||||
|
if emIn, err := extendable(in.Addr().Interface()); err == nil {
|
||||||
|
emOut, _ := extendable(out.Addr().Interface())
|
||||||
|
mIn, muIn := emIn.extensionsRead()
|
||||||
|
if mIn != nil {
|
||||||
|
mOut := emOut.extensionsWrite()
|
||||||
|
muIn.Lock()
|
||||||
|
mergeExtension(mOut, mIn)
|
||||||
|
muIn.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mi.unrecognized.IsValid() {
|
||||||
|
if b := *src.offset(mi.unrecognized).toBytes(); len(b) > 0 {
|
||||||
|
*dst.offset(mi.unrecognized).toBytes() = append([]byte(nil), b...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mi *mergeInfo) computeMergeInfo() {
|
||||||
|
mi.lock.Lock()
|
||||||
|
defer mi.lock.Unlock()
|
||||||
|
if mi.initialized != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := mi.typ
|
||||||
|
n := t.NumField()
|
||||||
|
|
||||||
|
props := GetProperties(t)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
f := t.Field(i)
|
||||||
|
if strings.HasPrefix(f.Name, "XXX_") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
mfi := mergeFieldInfo{field: toField(&f)}
|
||||||
|
tf := f.Type
|
||||||
|
|
||||||
|
// As an optimization, we can avoid the merge function call cost
|
||||||
|
// if we know for sure that the source will have no effect
|
||||||
|
// by checking if it is the zero value.
|
||||||
|
if unsafeAllowed {
|
||||||
|
switch tf.Kind() {
|
||||||
|
case reflect.Ptr, reflect.Slice, reflect.String:
|
||||||
|
// As a special case, we assume slices and strings are pointers
|
||||||
|
// since we know that the first field in the SliceSlice or
|
||||||
|
// StringHeader is a data pointer.
|
||||||
|
mfi.isPointer = true
|
||||||
|
case reflect.Bool:
|
||||||
|
mfi.basicWidth = 1
|
||||||
|
case reflect.Int32, reflect.Uint32, reflect.Float32:
|
||||||
|
mfi.basicWidth = 4
|
||||||
|
case reflect.Int64, reflect.Uint64, reflect.Float64:
|
||||||
|
mfi.basicWidth = 8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap tf to get at its most basic type.
|
||||||
|
var isPointer, isSlice bool
|
||||||
|
if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
|
||||||
|
isSlice = true
|
||||||
|
tf = tf.Elem()
|
||||||
|
}
|
||||||
|
if tf.Kind() == reflect.Ptr {
|
||||||
|
isPointer = true
|
||||||
|
tf = tf.Elem()
|
||||||
|
}
|
||||||
|
if isPointer && isSlice && tf.Kind() != reflect.Struct {
|
||||||
|
panic("both pointer and slice for basic type in " + tf.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tf.Kind() {
|
||||||
|
case reflect.Int32:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []int32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
// NOTE: toInt32Slice is not defined (see pointer_reflect.go).
|
||||||
|
/*
|
||||||
|
sfsp := src.toInt32Slice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toInt32Slice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []int64{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
sfs := src.getInt32Slice()
|
||||||
|
if sfs != nil {
|
||||||
|
dfs := dst.getInt32Slice()
|
||||||
|
dfs = append(dfs, sfs...)
|
||||||
|
if dfs == nil {
|
||||||
|
dfs = []int32{}
|
||||||
|
}
|
||||||
|
dst.setInt32Slice(dfs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *int32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
// NOTE: toInt32Ptr is not defined (see pointer_reflect.go).
|
||||||
|
/*
|
||||||
|
sfpp := src.toInt32Ptr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toInt32Ptr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Int32(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
sfp := src.getInt32Ptr()
|
||||||
|
if sfp != nil {
|
||||||
|
dfp := dst.getInt32Ptr()
|
||||||
|
if dfp == nil {
|
||||||
|
dst.setInt32Ptr(*sfp)
|
||||||
|
} else {
|
||||||
|
*dfp = *sfp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., int32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toInt32(); v != 0 {
|
||||||
|
*dst.toInt32() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Int64:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []int64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toInt64Slice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toInt64Slice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []int64{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *int64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toInt64Ptr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toInt64Ptr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Int64(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., int64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toInt64(); v != 0 {
|
||||||
|
*dst.toInt64() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Uint32:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []uint32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toUint32Slice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toUint32Slice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []uint32{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *uint32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toUint32Ptr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toUint32Ptr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Uint32(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., uint32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toUint32(); v != 0 {
|
||||||
|
*dst.toUint32() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Uint64:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []uint64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toUint64Slice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toUint64Slice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []uint64{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *uint64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toUint64Ptr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toUint64Ptr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Uint64(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., uint64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toUint64(); v != 0 {
|
||||||
|
*dst.toUint64() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Float32:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []float32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toFloat32Slice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toFloat32Slice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []float32{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *float32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toFloat32Ptr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toFloat32Ptr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Float32(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., float32
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toFloat32(); v != 0 {
|
||||||
|
*dst.toFloat32() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Float64:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []float64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toFloat64Slice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toFloat64Slice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []float64{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *float64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toFloat64Ptr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toFloat64Ptr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Float64(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., float64
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toFloat64(); v != 0 {
|
||||||
|
*dst.toFloat64() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Bool:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []bool
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toBoolSlice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toBoolSlice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []bool{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *bool
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toBoolPtr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toBoolPtr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = Bool(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., bool
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toBool(); v {
|
||||||
|
*dst.toBool() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.String:
|
||||||
|
switch {
|
||||||
|
case isSlice: // E.g., []string
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfsp := src.toStringSlice()
|
||||||
|
if *sfsp != nil {
|
||||||
|
dfsp := dst.toStringSlice()
|
||||||
|
*dfsp = append(*dfsp, *sfsp...)
|
||||||
|
if *dfsp == nil {
|
||||||
|
*dfsp = []string{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case isPointer: // E.g., *string
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sfpp := src.toStringPtr()
|
||||||
|
if *sfpp != nil {
|
||||||
|
dfpp := dst.toStringPtr()
|
||||||
|
if *dfpp == nil {
|
||||||
|
*dfpp = String(**sfpp)
|
||||||
|
} else {
|
||||||
|
**dfpp = **sfpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., string
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
if v := *src.toString(); v != "" {
|
||||||
|
*dst.toString() = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Slice:
|
||||||
|
isProto3 := props.Prop[i].proto3
|
||||||
|
switch {
|
||||||
|
case isPointer:
|
||||||
|
panic("bad pointer in byte slice case in " + tf.Name())
|
||||||
|
case tf.Elem().Kind() != reflect.Uint8:
|
||||||
|
panic("bad element kind in byte slice case in " + tf.Name())
|
||||||
|
case isSlice: // E.g., [][]byte
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sbsp := src.toBytesSlice()
|
||||||
|
if *sbsp != nil {
|
||||||
|
dbsp := dst.toBytesSlice()
|
||||||
|
for _, sb := range *sbsp {
|
||||||
|
if sb == nil {
|
||||||
|
*dbsp = append(*dbsp, nil)
|
||||||
|
} else {
|
||||||
|
*dbsp = append(*dbsp, append([]byte{}, sb...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if *dbsp == nil {
|
||||||
|
*dbsp = [][]byte{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., []byte
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sbp := src.toBytes()
|
||||||
|
if *sbp != nil {
|
||||||
|
dbp := dst.toBytes()
|
||||||
|
if !isProto3 || len(*sbp) > 0 {
|
||||||
|
*dbp = append([]byte{}, *sbp...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Struct:
|
||||||
|
switch {
|
||||||
|
case !isPointer:
|
||||||
|
panic(fmt.Sprintf("message field %s without pointer", tf))
|
||||||
|
case isSlice: // E.g., []*pb.T
|
||||||
|
mi := getMergeInfo(tf)
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sps := src.getPointerSlice()
|
||||||
|
if sps != nil {
|
||||||
|
dps := dst.getPointerSlice()
|
||||||
|
for _, sp := range sps {
|
||||||
|
var dp pointer
|
||||||
|
if !sp.isNil() {
|
||||||
|
dp = valToPointer(reflect.New(tf))
|
||||||
|
mi.merge(dp, sp)
|
||||||
|
}
|
||||||
|
dps = append(dps, dp)
|
||||||
|
}
|
||||||
|
if dps == nil {
|
||||||
|
dps = []pointer{}
|
||||||
|
}
|
||||||
|
dst.setPointerSlice(dps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // E.g., *pb.T
|
||||||
|
mi := getMergeInfo(tf)
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sp := src.getPointer()
|
||||||
|
if !sp.isNil() {
|
||||||
|
dp := dst.getPointer()
|
||||||
|
if dp.isNil() {
|
||||||
|
dp = valToPointer(reflect.New(tf))
|
||||||
|
dst.setPointer(dp)
|
||||||
|
}
|
||||||
|
mi.merge(dp, sp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Map:
|
||||||
|
switch {
|
||||||
|
case isPointer || isSlice:
|
||||||
|
panic("bad pointer or slice in map case in " + tf.Name())
|
||||||
|
default: // E.g., map[K]V
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
sm := src.asPointerTo(tf).Elem()
|
||||||
|
if sm.Len() == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dm := dst.asPointerTo(tf).Elem()
|
||||||
|
if dm.IsNil() {
|
||||||
|
dm.Set(reflect.MakeMap(tf))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tf.Elem().Kind() {
|
||||||
|
case reflect.Ptr: // Proto struct (e.g., *T)
|
||||||
|
for _, key := range sm.MapKeys() {
|
||||||
|
val := sm.MapIndex(key)
|
||||||
|
val = reflect.ValueOf(Clone(val.Interface().(Message)))
|
||||||
|
dm.SetMapIndex(key, val)
|
||||||
|
}
|
||||||
|
case reflect.Slice: // E.g. Bytes type (e.g., []byte)
|
||||||
|
for _, key := range sm.MapKeys() {
|
||||||
|
val := sm.MapIndex(key)
|
||||||
|
val = reflect.ValueOf(append([]byte{}, val.Bytes()...))
|
||||||
|
dm.SetMapIndex(key, val)
|
||||||
|
}
|
||||||
|
default: // Basic type (e.g., string)
|
||||||
|
for _, key := range sm.MapKeys() {
|
||||||
|
val := sm.MapIndex(key)
|
||||||
|
dm.SetMapIndex(key, val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reflect.Interface:
|
||||||
|
// Must be oneof field.
|
||||||
|
switch {
|
||||||
|
case isPointer || isSlice:
|
||||||
|
panic("bad pointer or slice in interface case in " + tf.Name())
|
||||||
|
default: // E.g., interface{}
|
||||||
|
// TODO: Make this faster?
|
||||||
|
mfi.merge = func(dst, src pointer) {
|
||||||
|
su := src.asPointerTo(tf).Elem()
|
||||||
|
if !su.IsNil() {
|
||||||
|
du := dst.asPointerTo(tf).Elem()
|
||||||
|
typ := su.Elem().Type()
|
||||||
|
if du.IsNil() || du.Elem().Type() != typ {
|
||||||
|
du.Set(reflect.New(typ.Elem())) // Initialize interface if empty
|
||||||
|
}
|
||||||
|
sv := su.Elem().Elem().Field(0)
|
||||||
|
if sv.Kind() == reflect.Ptr && sv.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dv := du.Elem().Elem().Field(0)
|
||||||
|
if dv.Kind() == reflect.Ptr && dv.IsNil() {
|
||||||
|
dv.Set(reflect.New(sv.Type().Elem())) // Initialize proto message if empty
|
||||||
|
}
|
||||||
|
switch sv.Type().Kind() {
|
||||||
|
case reflect.Ptr: // Proto struct (e.g., *T)
|
||||||
|
Merge(dv.Interface().(Message), sv.Interface().(Message))
|
||||||
|
case reflect.Slice: // E.g. Bytes type (e.g., []byte)
|
||||||
|
dv.Set(reflect.ValueOf(append([]byte{}, sv.Bytes()...)))
|
||||||
|
default: // Basic type (e.g., string)
|
||||||
|
dv.Set(sv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("merger not found for type:%s", tf))
|
||||||
|
}
|
||||||
|
mi.fields = append(mi.fields, mfi)
|
||||||
|
}
|
||||||
|
|
||||||
|
mi.unrecognized = invalidField
|
||||||
|
if f, ok := t.FieldByName("XXX_unrecognized"); ok {
|
||||||
|
if f.Type != reflect.TypeOf([]byte{}) {
|
||||||
|
panic("expected XXX_unrecognized to be of type []byte")
|
||||||
|
}
|
||||||
|
mi.unrecognized = toField(&f)
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.StoreInt32(&mi.initialized, 1)
|
||||||
|
}
|
||||||
2051
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/table_unmarshal.go
generated
vendored
Normal file
2051
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/table_unmarshal.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
63
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/text.go
generated
vendored
63
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/text.go
generated
vendored
|
|
@ -50,7 +50,6 @@ import (
|
||||||
var (
|
var (
|
||||||
newline = []byte("\n")
|
newline = []byte("\n")
|
||||||
spaces = []byte(" ")
|
spaces = []byte(" ")
|
||||||
gtNewline = []byte(">\n")
|
|
||||||
endBraceNewline = []byte("}\n")
|
endBraceNewline = []byte("}\n")
|
||||||
backslashN = []byte{'\\', 'n'}
|
backslashN = []byte{'\\', 'n'}
|
||||||
backslashR = []byte{'\\', 'r'}
|
backslashR = []byte{'\\', 'r'}
|
||||||
|
|
@ -170,11 +169,6 @@ func writeName(w *textWriter, props *Properties) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// raw is the interface satisfied by RawMessage.
|
|
||||||
type raw interface {
|
|
||||||
Bytes() []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func requiresQuotes(u string) bool {
|
func requiresQuotes(u string) bool {
|
||||||
// When type URL contains any characters except [0-9A-Za-z./\-]*, it must be quoted.
|
// When type URL contains any characters except [0-9A-Za-z./\-]*, it must be quoted.
|
||||||
for _, ch := range u {
|
for _, ch := range u {
|
||||||
|
|
@ -269,6 +263,10 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||||
props := sprops.Prop[i]
|
props := sprops.Prop[i]
|
||||||
name := st.Field(i).Name
|
name := st.Field(i).Name
|
||||||
|
|
||||||
|
if name == "XXX_NoUnkeyedLiteral" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(name, "XXX_") {
|
if strings.HasPrefix(name, "XXX_") {
|
||||||
// There are two XXX_ fields:
|
// There are two XXX_ fields:
|
||||||
// XXX_unrecognized []byte
|
// XXX_unrecognized []byte
|
||||||
|
|
@ -355,7 +353,7 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := tm.writeAny(w, key, props.mkeyprop); err != nil {
|
if err := tm.writeAny(w, key, props.MapKeyProp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := w.WriteByte('\n'); err != nil {
|
if err := w.WriteByte('\n'); err != nil {
|
||||||
|
|
@ -372,7 +370,7 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := tm.writeAny(w, val, props.mvalprop); err != nil {
|
if err := tm.writeAny(w, val, props.MapValProp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := w.WriteByte('\n'); err != nil {
|
if err := w.WriteByte('\n'); err != nil {
|
||||||
|
|
@ -436,12 +434,6 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if b, ok := fv.Interface().(raw); ok {
|
|
||||||
if err := writeRaw(w, b.Bytes()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enums have a String method, so writeAny will work fine.
|
// Enums have a String method, so writeAny will work fine.
|
||||||
if err := tm.writeAny(w, fv, props); err != nil {
|
if err := tm.writeAny(w, fv, props); err != nil {
|
||||||
|
|
@ -455,7 +447,7 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||||
|
|
||||||
// Extensions (the XXX_extensions field).
|
// Extensions (the XXX_extensions field).
|
||||||
pv := sv.Addr()
|
pv := sv.Addr()
|
||||||
if _, ok := extendable(pv.Interface()); ok {
|
if _, err := extendable(pv.Interface()); err == nil {
|
||||||
if err := tm.writeExtensions(w, pv); err != nil {
|
if err := tm.writeExtensions(w, pv); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -464,27 +456,6 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeRaw writes an uninterpreted raw message.
|
|
||||||
func writeRaw(w *textWriter, b []byte) error {
|
|
||||||
if err := w.WriteByte('<'); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !w.compact {
|
|
||||||
if err := w.WriteByte('\n'); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.indent()
|
|
||||||
if err := writeUnknownStruct(w, b); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.unindent()
|
|
||||||
if err := w.WriteByte('>'); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeAny writes an arbitrary field.
|
// writeAny writes an arbitrary field.
|
||||||
func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
|
func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
|
||||||
v = reflect.Indirect(v)
|
v = reflect.Indirect(v)
|
||||||
|
|
@ -535,6 +506,19 @@ func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Propert
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.indent()
|
w.indent()
|
||||||
|
if v.CanAddr() {
|
||||||
|
// Calling v.Interface on a struct causes the reflect package to
|
||||||
|
// copy the entire struct. This is racy with the new Marshaler
|
||||||
|
// since we atomically update the XXX_sizecache.
|
||||||
|
//
|
||||||
|
// Thus, we retrieve a pointer to the struct if possible to avoid
|
||||||
|
// a race since v.Interface on the pointer doesn't copy the struct.
|
||||||
|
//
|
||||||
|
// If v is not addressable, then we are not worried about a race
|
||||||
|
// since it implies that the binary Marshaler cannot possibly be
|
||||||
|
// mutating this value.
|
||||||
|
v = v.Addr()
|
||||||
|
}
|
||||||
if etm, ok := v.Interface().(encoding.TextMarshaler); ok {
|
if etm, ok := v.Interface().(encoding.TextMarshaler); ok {
|
||||||
text, err := etm.MarshalText()
|
text, err := etm.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -543,9 +527,14 @@ func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Propert
|
||||||
if _, err = w.Write(text); err != nil {
|
if _, err = w.Write(text); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if err := tm.writeStruct(w, v); err != nil {
|
} else {
|
||||||
|
if v.Kind() == reflect.Ptr {
|
||||||
|
v = v.Elem()
|
||||||
|
}
|
||||||
|
if err := tm.writeStruct(w, v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
w.unindent()
|
w.unindent()
|
||||||
if err := w.WriteByte(ket); err != nil {
|
if err := w.WriteByte(ket); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
83
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/text_parser.go
generated
vendored
83
chaincode/abac/go/vendor/github.com/golang/protobuf/proto/text_parser.go
generated
vendored
|
|
@ -206,7 +206,6 @@ func (p *textParser) advance() {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errBadUTF8 = errors.New("proto: bad UTF-8")
|
errBadUTF8 = errors.New("proto: bad UTF-8")
|
||||||
errBadHex = errors.New("proto: bad hexadecimal")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func unquoteC(s string, quote rune) (string, error) {
|
func unquoteC(s string, quote rune) (string, error) {
|
||||||
|
|
@ -277,60 +276,47 @@ func unescape(s string) (ch string, tail string, err error) {
|
||||||
return "?", s, nil // trigraph workaround
|
return "?", s, nil // trigraph workaround
|
||||||
case '\'', '"', '\\':
|
case '\'', '"', '\\':
|
||||||
return string(r), s, nil
|
return string(r), s, nil
|
||||||
case '0', '1', '2', '3', '4', '5', '6', '7', 'x', 'X':
|
case '0', '1', '2', '3', '4', '5', '6', '7':
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
|
return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
|
||||||
}
|
}
|
||||||
base := 8
|
ss := string(r) + s[:2]
|
||||||
ss := s[:2]
|
|
||||||
s = s[2:]
|
s = s[2:]
|
||||||
if r == 'x' || r == 'X' {
|
i, err := strconv.ParseUint(ss, 8, 8)
|
||||||
base = 16
|
|
||||||
} else {
|
|
||||||
ss = string(r) + ss
|
|
||||||
}
|
|
||||||
i, err := strconv.ParseUint(ss, base, 8)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", fmt.Errorf(`\%s contains non-octal digits`, ss)
|
||||||
}
|
}
|
||||||
return string([]byte{byte(i)}), s, nil
|
return string([]byte{byte(i)}), s, nil
|
||||||
case 'u', 'U':
|
case 'x', 'X', 'u', 'U':
|
||||||
n := 4
|
var n int
|
||||||
if r == 'U' {
|
switch r {
|
||||||
|
case 'x', 'X':
|
||||||
|
n = 2
|
||||||
|
case 'u':
|
||||||
|
n = 4
|
||||||
|
case 'U':
|
||||||
n = 8
|
n = 8
|
||||||
}
|
}
|
||||||
if len(s) < n {
|
if len(s) < n {
|
||||||
return "", "", fmt.Errorf(`\%c requires %d digits`, r, n)
|
return "", "", fmt.Errorf(`\%c requires %d following digits`, r, n)
|
||||||
}
|
|
||||||
|
|
||||||
bs := make([]byte, n/2)
|
|
||||||
for i := 0; i < n; i += 2 {
|
|
||||||
a, ok1 := unhex(s[i])
|
|
||||||
b, ok2 := unhex(s[i+1])
|
|
||||||
if !ok1 || !ok2 {
|
|
||||||
return "", "", errBadHex
|
|
||||||
}
|
|
||||||
bs[i/2] = a<<4 | b
|
|
||||||
}
|
}
|
||||||
|
ss := s[:n]
|
||||||
s = s[n:]
|
s = s[n:]
|
||||||
return string(bs), s, nil
|
i, err := strconv.ParseUint(ss, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", fmt.Errorf(`\%c%s contains non-hexadecimal digits`, r, ss)
|
||||||
|
}
|
||||||
|
if r == 'x' || r == 'X' {
|
||||||
|
return string([]byte{byte(i)}), s, nil
|
||||||
|
}
|
||||||
|
if i > utf8.MaxRune {
|
||||||
|
return "", "", fmt.Errorf(`\%c%s is not a valid Unicode code point`, r, ss)
|
||||||
|
}
|
||||||
|
return string(i), s, nil
|
||||||
}
|
}
|
||||||
return "", "", fmt.Errorf(`unknown escape \%c`, r)
|
return "", "", fmt.Errorf(`unknown escape \%c`, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adapted from src/pkg/strconv/quote.go.
|
|
||||||
func unhex(b byte) (v byte, ok bool) {
|
|
||||||
switch {
|
|
||||||
case '0' <= b && b <= '9':
|
|
||||||
return b - '0', true
|
|
||||||
case 'a' <= b && b <= 'f':
|
|
||||||
return b - 'a' + 10, true
|
|
||||||
case 'A' <= b && b <= 'F':
|
|
||||||
return b - 'A' + 10, true
|
|
||||||
}
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Back off the parser by one token. Can only be done between calls to next().
|
// Back off the parser by one token. Can only be done between calls to next().
|
||||||
// It makes the next advance() a no-op.
|
// It makes the next advance() a no-op.
|
||||||
func (p *textParser) back() { p.backed = true }
|
func (p *textParser) back() { p.backed = true }
|
||||||
|
|
@ -644,17 +630,17 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) error {
|
||||||
if err := p.consumeToken(":"); err != nil {
|
if err := p.consumeToken(":"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.readAny(key, props.mkeyprop); err != nil {
|
if err := p.readAny(key, props.MapKeyProp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.consumeOptionalSeparator(); err != nil {
|
if err := p.consumeOptionalSeparator(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case "value":
|
case "value":
|
||||||
if err := p.checkForColon(props.mvalprop, dst.Type().Elem()); err != nil {
|
if err := p.checkForColon(props.MapValProp, dst.Type().Elem()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.readAny(val, props.mvalprop); err != nil {
|
if err := p.readAny(val, props.MapValProp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.consumeOptionalSeparator(); err != nil {
|
if err := p.consumeOptionalSeparator(); err != nil {
|
||||||
|
|
@ -728,6 +714,9 @@ func (p *textParser) consumeExtName() (string, error) {
|
||||||
if tok.err != nil {
|
if tok.err != nil {
|
||||||
return "", p.errorf("unrecognized type_url or extension name: %s", tok.err)
|
return "", p.errorf("unrecognized type_url or extension name: %s", tok.err)
|
||||||
}
|
}
|
||||||
|
if p.done && tok.value != "]" {
|
||||||
|
return "", p.errorf("unclosed type_url or extension name")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(parts, ""), nil
|
return strings.Join(parts, ""), nil
|
||||||
}
|
}
|
||||||
|
|
@ -865,7 +854,7 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) error {
|
||||||
return p.readStruct(fv, terminator)
|
return p.readStruct(fv, terminator)
|
||||||
case reflect.Uint32:
|
case reflect.Uint32:
|
||||||
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
|
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
|
||||||
fv.SetUint(x)
|
fv.SetUint(uint64(x))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case reflect.Uint64:
|
case reflect.Uint64:
|
||||||
|
|
@ -883,13 +872,9 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) error {
|
||||||
// UnmarshalText returns *RequiredNotSetError.
|
// UnmarshalText returns *RequiredNotSetError.
|
||||||
func UnmarshalText(s string, pb Message) error {
|
func UnmarshalText(s string, pb Message) error {
|
||||||
if um, ok := pb.(encoding.TextUnmarshaler); ok {
|
if um, ok := pb.(encoding.TextUnmarshaler); ok {
|
||||||
err := um.UnmarshalText([]byte(s))
|
return um.UnmarshalText([]byte(s))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
pb.Reset()
|
pb.Reset()
|
||||||
v := reflect.ValueOf(pb)
|
v := reflect.ValueOf(pb)
|
||||||
if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil {
|
return newTextParser(s).readStruct(v.Elem(), "")
|
||||||
return pe
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/hyperledger/fabric/protos/msp"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -132,6 +134,54 @@ func (mgr *Mgr) GetAttributesFromCert(cert *x509.Certificate) (*Attributes, erro
|
||||||
return attrs, nil
|
return attrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mgr *Mgr) GetAttributesFromIdemix(creator []byte) (*Attributes, error) {
|
||||||
|
if creator == nil {
|
||||||
|
return nil, errors.New("creator is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
sid := &msp.SerializedIdentity{}
|
||||||
|
err := proto.Unmarshal(creator, sid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's identity")
|
||||||
|
}
|
||||||
|
idemixID := &msp.SerializedIdemixIdentity{}
|
||||||
|
err = proto.Unmarshal(sid.IdBytes, idemixID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's idemix identity")
|
||||||
|
}
|
||||||
|
// Unmarshal into attributes object
|
||||||
|
attrs := &Attributes{
|
||||||
|
Attrs: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
ou := &msp.OrganizationUnit{}
|
||||||
|
err = proto.Unmarshal(idemixID.Ou, ou)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's ou")
|
||||||
|
}
|
||||||
|
attrs.Attrs["ou"] = ou.OrganizationalUnitIdentifier
|
||||||
|
|
||||||
|
role := &msp.MSPRole{}
|
||||||
|
err = proto.Unmarshal(idemixID.Role, role)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's role")
|
||||||
|
}
|
||||||
|
var roleStr string
|
||||||
|
switch role.Role {
|
||||||
|
case 0:
|
||||||
|
roleStr = "member"
|
||||||
|
case 1:
|
||||||
|
roleStr = "admin"
|
||||||
|
case 2:
|
||||||
|
roleStr = "client"
|
||||||
|
case 3:
|
||||||
|
roleStr = "peer"
|
||||||
|
}
|
||||||
|
attrs.Attrs["role"] = roleStr
|
||||||
|
|
||||||
|
return attrs, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Attributes contains attribute names and values
|
// Attributes contains attribute names and values
|
||||||
type Attributes struct {
|
type Attributes struct {
|
||||||
Attrs map[string]string `json:"attrs"`
|
Attrs map[string]string `json:"attrs"`
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/hyperledger/fabric/common/attrmgr"
|
"github.com/hyperledger/fabric/core/chaincode/shim/ext/attrmgr"
|
||||||
"github.com/hyperledger/fabric/protos/msp"
|
"github.com/hyperledger/fabric/protos/msp"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
@ -99,7 +99,7 @@ func New(stub ChaincodeStubInterface) (ClientIdentity, error) {
|
||||||
|
|
||||||
// GetID returns a unique ID associated with the invoking identity.
|
// GetID returns a unique ID associated with the invoking identity.
|
||||||
func (c *clientIdentityImpl) GetID() (string, error) {
|
func (c *clientIdentityImpl) GetID() (string, error) {
|
||||||
// The leading "x509::" distinquishes this as an X509 certificate, and
|
// The leading "x509::" distinguishes this as an X509 certificate, and
|
||||||
// the subject and issuer DNs uniquely identify the X509 certificate.
|
// the subject and issuer DNs uniquely identify the X509 certificate.
|
||||||
// The resulting ID will remain the same if the certificate is renewed.
|
// The resulting ID will remain the same if the certificate is renewed.
|
||||||
id := fmt.Sprintf("x509::%s::%s", getDN(&c.cert.Subject), getDN(&c.cert.Issuer))
|
id := fmt.Sprintf("x509::%s::%s", getDN(&c.cert.Subject), getDN(&c.cert.Issuer))
|
||||||
|
|
@ -151,11 +151,15 @@ func (c *clientIdentityImpl) init() error {
|
||||||
idbytes := signingID.GetIdBytes()
|
idbytes := signingID.GetIdBytes()
|
||||||
block, _ := pem.Decode(idbytes)
|
block, _ := pem.Decode(idbytes)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return errors.New("Expecting a PEM-encoded X509 certificate; PEM block not found")
|
err := c.getAttributesFromIdemix()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "identity bytes are neither X509 PEM format nor an idemix credential")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
cert, err := x509.ParseCertificate(block.Bytes)
|
cert, err := x509.ParseCertificate(block.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to parse certificate")
|
return errors.WithMessage(err, "failed to parse certificate")
|
||||||
}
|
}
|
||||||
c.cert = cert
|
c.cert = cert
|
||||||
attrs, err := attrmgr.New().GetAttributesFromCert(cert)
|
attrs, err := attrmgr.New().GetAttributesFromCert(cert)
|
||||||
|
|
@ -181,7 +185,17 @@ func (c *clientIdentityImpl) getIdentity() (*msp.SerializedIdentity, error) {
|
||||||
return sid, nil
|
return sid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the DN (distinquished name) associated with a pkix.Name.
|
func (c *clientIdentityImpl) getAttributesFromIdemix() error {
|
||||||
|
creator, err := c.stub.GetCreator()
|
||||||
|
attrs, err := attrmgr.New().GetAttributesFromIdemix(creator)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "failed to get attributes from the transaction invoker's idemix credential")
|
||||||
|
}
|
||||||
|
c.attrs = attrs
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the DN (distinguished name) associated with a pkix.Name.
|
||||||
// NOTE: This code is almost a direct copy of the String() function in
|
// NOTE: This code is almost a direct copy of the String() function in
|
||||||
// https://go-review.googlesource.com/c/go/+/67270/1/src/crypto/x509/pkix/pkix.go#26
|
// https://go-review.googlesource.com/c/go/+/67270/1/src/crypto/x509/pkix/pkix.go#26
|
||||||
// which returns a DN as defined by RFC 2253.
|
// which returns a DN as defined by RFC 2253.
|
||||||
179
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/identities.pb.go
generated
vendored
Normal file
179
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/identities.pb.go
generated
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// source: msp/identities.proto
|
||||||
|
|
||||||
|
package msp // import "github.com/hyperledger/fabric/protos/msp"
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
// This struct represents an Identity
|
||||||
|
// (with its MSP identifier) to be used
|
||||||
|
// to serialize it and deserialize it
|
||||||
|
type SerializedIdentity struct {
|
||||||
|
// The identifier of the associated membership service provider
|
||||||
|
Mspid string `protobuf:"bytes,1,opt,name=mspid,proto3" json:"mspid,omitempty"`
|
||||||
|
// the Identity, serialized according to the rules of its MPS
|
||||||
|
IdBytes []byte `protobuf:"bytes,2,opt,name=id_bytes,json=idBytes,proto3" json:"id_bytes,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdentity) Reset() { *m = SerializedIdentity{} }
|
||||||
|
func (m *SerializedIdentity) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SerializedIdentity) ProtoMessage() {}
|
||||||
|
func (*SerializedIdentity) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_identities_8fa8af3e5bf2070a, []int{0}
|
||||||
|
}
|
||||||
|
func (m *SerializedIdentity) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_SerializedIdentity.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *SerializedIdentity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_SerializedIdentity.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *SerializedIdentity) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_SerializedIdentity.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *SerializedIdentity) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_SerializedIdentity.Size(m)
|
||||||
|
}
|
||||||
|
func (m *SerializedIdentity) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_SerializedIdentity.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_SerializedIdentity proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *SerializedIdentity) GetMspid() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Mspid
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdentity) GetIdBytes() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.IdBytes
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This struct represents an Idemix Identity
|
||||||
|
// to be used to serialize it and deserialize it.
|
||||||
|
// The IdemixMSP will first serialize an idemix identity to bytes using
|
||||||
|
// this proto, and then uses these bytes as id_bytes in SerializedIdentity
|
||||||
|
type SerializedIdemixIdentity struct {
|
||||||
|
// nym_x is the X-component of the pseudonym elliptic curve point.
|
||||||
|
// It is a []byte representation of an amcl.BIG
|
||||||
|
// The pseudonym can be seen as a public key of the identity, it is used to verify signatures.
|
||||||
|
NymX []byte `protobuf:"bytes,1,opt,name=nym_x,json=nymX,proto3" json:"nym_x,omitempty"`
|
||||||
|
// nym_y is the Y-component of the pseudonym elliptic curve point.
|
||||||
|
// It is a []byte representation of an amcl.BIG
|
||||||
|
// The pseudonym can be seen as a public key of the identity, it is used to verify signatures.
|
||||||
|
NymY []byte `protobuf:"bytes,2,opt,name=nym_y,json=nymY,proto3" json:"nym_y,omitempty"`
|
||||||
|
// ou contains the organizational unit of the idemix identity
|
||||||
|
Ou []byte `protobuf:"bytes,3,opt,name=ou,proto3" json:"ou,omitempty"`
|
||||||
|
// role contains the role of this identity (e.g., ADMIN or MEMBER)
|
||||||
|
Role []byte `protobuf:"bytes,4,opt,name=role,proto3" json:"role,omitempty"`
|
||||||
|
// proof contains the cryptographic evidence that this identity is valid
|
||||||
|
Proof []byte `protobuf:"bytes,5,opt,name=proof,proto3" json:"proof,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdemixIdentity) Reset() { *m = SerializedIdemixIdentity{} }
|
||||||
|
func (m *SerializedIdemixIdentity) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SerializedIdemixIdentity) ProtoMessage() {}
|
||||||
|
func (*SerializedIdemixIdentity) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_identities_8fa8af3e5bf2070a, []int{1}
|
||||||
|
}
|
||||||
|
func (m *SerializedIdemixIdentity) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_SerializedIdemixIdentity.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *SerializedIdemixIdentity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_SerializedIdemixIdentity.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *SerializedIdemixIdentity) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_SerializedIdemixIdentity.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *SerializedIdemixIdentity) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_SerializedIdemixIdentity.Size(m)
|
||||||
|
}
|
||||||
|
func (m *SerializedIdemixIdentity) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_SerializedIdemixIdentity.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_SerializedIdemixIdentity proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *SerializedIdemixIdentity) GetNymX() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.NymX
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdemixIdentity) GetNymY() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.NymY
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdemixIdentity) GetOu() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Ou
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdemixIdentity) GetRole() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Role
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SerializedIdemixIdentity) GetProof() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Proof
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*SerializedIdentity)(nil), "msp.SerializedIdentity")
|
||||||
|
proto.RegisterType((*SerializedIdemixIdentity)(nil), "msp.SerializedIdemixIdentity")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("msp/identities.proto", fileDescriptor_identities_8fa8af3e5bf2070a) }
|
||||||
|
|
||||||
|
var fileDescriptor_identities_8fa8af3e5bf2070a = []byte{
|
||||||
|
// 238 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8f, 0x3f, 0x4f, 0xc3, 0x30,
|
||||||
|
0x10, 0x47, 0x95, 0x34, 0xe1, 0x8f, 0x55, 0x31, 0x98, 0x0e, 0x66, 0x2b, 0x9d, 0x32, 0xc5, 0x03,
|
||||||
|
0xdf, 0xa0, 0x12, 0x03, 0x03, 0x4b, 0x58, 0x80, 0xa5, 0x6a, 0xea, 0x6b, 0x7a, 0x52, 0x2e, 0x67,
|
||||||
|
0xd9, 0x8e, 0x54, 0x33, 0xf0, 0xd9, 0x51, 0x62, 0x40, 0xb0, 0xdd, 0xef, 0xe9, 0xe9, 0xc9, 0x16,
|
||||||
|
0x2b, 0xf2, 0x56, 0xa3, 0x81, 0x21, 0x60, 0x40, 0xf0, 0xb5, 0x75, 0x1c, 0x58, 0x2e, 0xc8, 0xdb,
|
||||||
|
0xcd, 0xa3, 0x90, 0x2f, 0xe0, 0x70, 0xdf, 0xe3, 0x07, 0x98, 0xa7, 0xa4, 0x44, 0xb9, 0x12, 0x25,
|
||||||
|
0x79, 0x8b, 0x46, 0x65, 0xeb, 0xac, 0xba, 0x6e, 0xd2, 0x90, 0x77, 0xe2, 0x0a, 0xcd, 0xae, 0x8d,
|
||||||
|
0x01, 0xbc, 0xca, 0xd7, 0x59, 0xb5, 0x6c, 0x2e, 0xd1, 0x6c, 0xa7, 0xb9, 0xf9, 0x14, 0xea, 0x5f,
|
||||||
|
0x86, 0xf0, 0xfc, 0x1b, 0xbb, 0x15, 0xe5, 0x10, 0x69, 0x77, 0x9e, 0x63, 0xcb, 0xa6, 0x18, 0x22,
|
||||||
|
0xbd, 0xfe, 0xc0, 0xf8, 0x1d, 0x9a, 0xe0, 0x9b, 0xbc, 0x11, 0x39, 0x8f, 0x6a, 0x31, 0x93, 0x9c,
|
||||||
|
0x47, 0x29, 0x45, 0xe1, 0xb8, 0x07, 0x55, 0x24, 0x67, 0xba, 0xa7, 0xa7, 0x59, 0xc7, 0x7c, 0x54,
|
||||||
|
0xe5, 0x0c, 0xd3, 0xd8, 0x3e, 0x8b, 0x7b, 0x76, 0x5d, 0x7d, 0x8a, 0x16, 0x5c, 0x0f, 0xa6, 0x03,
|
||||||
|
0x57, 0x1f, 0xf7, 0xad, 0xc3, 0x43, 0xfa, 0xab, 0xaf, 0xc9, 0xdb, 0xf7, 0xaa, 0xc3, 0x70, 0x1a,
|
||||||
|
0xdb, 0xfa, 0xc0, 0xa4, 0xff, 0x98, 0x3a, 0x99, 0x3a, 0x99, 0x9a, 0xbc, 0x6d, 0x2f, 0xe6, 0xfb,
|
||||||
|
0xe1, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x13, 0xdc, 0xc8, 0x62, 0x39, 0x01, 0x00, 0x00,
|
||||||
|
}
|
||||||
49
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/identities.proto
generated
vendored
Normal file
49
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/identities.proto
generated
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
Copyright IBM Corp. All Rights Reserved.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option go_package = "github.com/hyperledger/fabric/protos/msp";
|
||||||
|
option java_package = "org.hyperledger.fabric.protos.msp";
|
||||||
|
|
||||||
|
package msp;
|
||||||
|
|
||||||
|
// This struct represents an Identity
|
||||||
|
// (with its MSP identifier) to be used
|
||||||
|
// to serialize it and deserialize it
|
||||||
|
message SerializedIdentity {
|
||||||
|
// The identifier of the associated membership service provider
|
||||||
|
string mspid = 1;
|
||||||
|
|
||||||
|
// the Identity, serialized according to the rules of its MPS
|
||||||
|
bytes id_bytes = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This struct represents an Idemix Identity
|
||||||
|
// to be used to serialize it and deserialize it.
|
||||||
|
// The IdemixMSP will first serialize an idemix identity to bytes using
|
||||||
|
// this proto, and then uses these bytes as id_bytes in SerializedIdentity
|
||||||
|
message SerializedIdemixIdentity {
|
||||||
|
// nym_x is the X-component of the pseudonym elliptic curve point.
|
||||||
|
// It is a []byte representation of an amcl.BIG
|
||||||
|
// The pseudonym can be seen as a public key of the identity, it is used to verify signatures.
|
||||||
|
bytes nym_x = 1;
|
||||||
|
|
||||||
|
// nym_y is the Y-component of the pseudonym elliptic curve point.
|
||||||
|
// It is a []byte representation of an amcl.BIG
|
||||||
|
// The pseudonym can be seen as a public key of the identity, it is used to verify signatures.
|
||||||
|
bytes nym_y = 2;
|
||||||
|
|
||||||
|
// ou contains the organizational unit of the idemix identity
|
||||||
|
bytes ou = 3;
|
||||||
|
|
||||||
|
// role contains the role of this identity (e.g., ADMIN or MEMBER)
|
||||||
|
bytes role = 4;
|
||||||
|
|
||||||
|
// proof contains the cryptographic evidence that this identity is valid
|
||||||
|
bytes proof = 5;
|
||||||
|
}
|
||||||
41
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_config.go
generated
vendored
Normal file
41
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_config.go
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
Copyright IBM Corp. 2017 All Rights Reserved.
|
||||||
|
|
||||||
|
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 msp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (mc *MSPConfig) VariablyOpaqueFields() []string {
|
||||||
|
return []string{"config"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mc *MSPConfig) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
|
||||||
|
if name != mc.VariablyOpaqueFields()[0] {
|
||||||
|
return nil, fmt.Errorf("not a marshaled field: %s", name)
|
||||||
|
}
|
||||||
|
switch mc.Type {
|
||||||
|
case 0:
|
||||||
|
return &FabricMSPConfig{}, nil
|
||||||
|
case 1:
|
||||||
|
return &IdemixMSPConfig{}, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unable to decode MSP type: %v", mc.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
743
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_config.pb.go
generated
vendored
Normal file
743
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_config.pb.go
generated
vendored
Normal file
|
|
@ -0,0 +1,743 @@
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// source: msp/msp_config.proto
|
||||||
|
|
||||||
|
package msp // import "github.com/hyperledger/fabric/protos/msp"
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
// MSPConfig collects all the configuration information for
|
||||||
|
// an MSP. The Config field should be unmarshalled in a way
|
||||||
|
// that depends on the Type
|
||||||
|
type MSPConfig struct {
|
||||||
|
// Type holds the type of the MSP; the default one would
|
||||||
|
// be of type FABRIC implementing an X.509 based provider
|
||||||
|
Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"`
|
||||||
|
// Config is MSP dependent configuration info
|
||||||
|
Config []byte `protobuf:"bytes,2,opt,name=config,proto3" json:"config,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPConfig) Reset() { *m = MSPConfig{} }
|
||||||
|
func (m *MSPConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*MSPConfig) ProtoMessage() {}
|
||||||
|
func (*MSPConfig) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{0}
|
||||||
|
}
|
||||||
|
func (m *MSPConfig) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_MSPConfig.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *MSPConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_MSPConfig.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *MSPConfig) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_MSPConfig.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *MSPConfig) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_MSPConfig.Size(m)
|
||||||
|
}
|
||||||
|
func (m *MSPConfig) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_MSPConfig.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_MSPConfig proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *MSPConfig) GetType() int32 {
|
||||||
|
if m != nil {
|
||||||
|
return m.Type
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPConfig) GetConfig() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Config
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricMSPConfig collects all the configuration information for
|
||||||
|
// a Fabric MSP.
|
||||||
|
// Here we assume a default certificate validation policy, where
|
||||||
|
// any certificate signed by any of the listed rootCA certs would
|
||||||
|
// be considered as valid under this MSP.
|
||||||
|
// This MSP may or may not come with a signing identity. If it does,
|
||||||
|
// it can also issue signing identities. If it does not, it can only
|
||||||
|
// be used to validate and verify certificates.
|
||||||
|
type FabricMSPConfig struct {
|
||||||
|
// Name holds the identifier of the MSP; MSP identifier
|
||||||
|
// is chosen by the application that governs this MSP.
|
||||||
|
// For example, and assuming the default implementation of MSP,
|
||||||
|
// that is X.509-based and considers a single Issuer,
|
||||||
|
// this can refer to the Subject OU field or the Issuer OU field.
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
// List of root certificates trusted by this MSP
|
||||||
|
// they are used upon certificate validation (see
|
||||||
|
// comment for IntermediateCerts below)
|
||||||
|
RootCerts [][]byte `protobuf:"bytes,2,rep,name=root_certs,json=rootCerts,proto3" json:"root_certs,omitempty"`
|
||||||
|
// List of intermediate certificates trusted by this MSP;
|
||||||
|
// they are used upon certificate validation as follows:
|
||||||
|
// validation attempts to build a path from the certificate
|
||||||
|
// to be validated (which is at one end of the path) and
|
||||||
|
// one of the certs in the RootCerts field (which is at
|
||||||
|
// the other end of the path). If the path is longer than
|
||||||
|
// 2, certificates in the middle are searched within the
|
||||||
|
// IntermediateCerts pool
|
||||||
|
IntermediateCerts [][]byte `protobuf:"bytes,3,rep,name=intermediate_certs,json=intermediateCerts,proto3" json:"intermediate_certs,omitempty"`
|
||||||
|
// Identity denoting the administrator of this MSP
|
||||||
|
Admins [][]byte `protobuf:"bytes,4,rep,name=admins,proto3" json:"admins,omitempty"`
|
||||||
|
// Identity revocation list
|
||||||
|
RevocationList [][]byte `protobuf:"bytes,5,rep,name=revocation_list,json=revocationList,proto3" json:"revocation_list,omitempty"`
|
||||||
|
// SigningIdentity holds information on the signing identity
|
||||||
|
// this peer is to use, and which is to be imported by the
|
||||||
|
// MSP defined before
|
||||||
|
SigningIdentity *SigningIdentityInfo `protobuf:"bytes,6,opt,name=signing_identity,json=signingIdentity,proto3" json:"signing_identity,omitempty"`
|
||||||
|
// OrganizationalUnitIdentifiers holds one or more
|
||||||
|
// fabric organizational unit identifiers that belong to
|
||||||
|
// this MSP configuration
|
||||||
|
OrganizationalUnitIdentifiers []*FabricOUIdentifier `protobuf:"bytes,7,rep,name=organizational_unit_identifiers,json=organizationalUnitIdentifiers,proto3" json:"organizational_unit_identifiers,omitempty"`
|
||||||
|
// FabricCryptoConfig contains the configuration parameters
|
||||||
|
// for the cryptographic algorithms used by this MSP
|
||||||
|
CryptoConfig *FabricCryptoConfig `protobuf:"bytes,8,opt,name=crypto_config,json=cryptoConfig,proto3" json:"crypto_config,omitempty"`
|
||||||
|
// List of TLS root certificates trusted by this MSP.
|
||||||
|
// They are returned by GetTLSRootCerts.
|
||||||
|
TlsRootCerts [][]byte `protobuf:"bytes,9,rep,name=tls_root_certs,json=tlsRootCerts,proto3" json:"tls_root_certs,omitempty"`
|
||||||
|
// List of TLS intermediate certificates trusted by this MSP;
|
||||||
|
// They are returned by GetTLSIntermediateCerts.
|
||||||
|
TlsIntermediateCerts [][]byte `protobuf:"bytes,10,rep,name=tls_intermediate_certs,json=tlsIntermediateCerts,proto3" json:"tls_intermediate_certs,omitempty"`
|
||||||
|
// fabric_node_ous contains the configuration to distinguish clients from peers from orderers
|
||||||
|
// based on the OUs.
|
||||||
|
FabricNodeOus *FabricNodeOUs `protobuf:"bytes,11,opt,name=fabric_node_ous,json=fabricNodeOus,proto3" json:"fabric_node_ous,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) Reset() { *m = FabricMSPConfig{} }
|
||||||
|
func (m *FabricMSPConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*FabricMSPConfig) ProtoMessage() {}
|
||||||
|
func (*FabricMSPConfig) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{1}
|
||||||
|
}
|
||||||
|
func (m *FabricMSPConfig) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_FabricMSPConfig.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *FabricMSPConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_FabricMSPConfig.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *FabricMSPConfig) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_FabricMSPConfig.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *FabricMSPConfig) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_FabricMSPConfig.Size(m)
|
||||||
|
}
|
||||||
|
func (m *FabricMSPConfig) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_FabricMSPConfig.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_FabricMSPConfig proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetName() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetRootCerts() [][]byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.RootCerts
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetIntermediateCerts() [][]byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.IntermediateCerts
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetAdmins() [][]byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Admins
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetRevocationList() [][]byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.RevocationList
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetSigningIdentity() *SigningIdentityInfo {
|
||||||
|
if m != nil {
|
||||||
|
return m.SigningIdentity
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetOrganizationalUnitIdentifiers() []*FabricOUIdentifier {
|
||||||
|
if m != nil {
|
||||||
|
return m.OrganizationalUnitIdentifiers
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetCryptoConfig() *FabricCryptoConfig {
|
||||||
|
if m != nil {
|
||||||
|
return m.CryptoConfig
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetTlsRootCerts() [][]byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.TlsRootCerts
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetTlsIntermediateCerts() [][]byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.TlsIntermediateCerts
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricMSPConfig) GetFabricNodeOus() *FabricNodeOUs {
|
||||||
|
if m != nil {
|
||||||
|
return m.FabricNodeOus
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricCryptoConfig contains configuration parameters
|
||||||
|
// for the cryptographic algorithms used by the MSP
|
||||||
|
// this configuration refers to
|
||||||
|
type FabricCryptoConfig struct {
|
||||||
|
// SignatureHashFamily is a string representing the hash family to be used
|
||||||
|
// during sign and verify operations.
|
||||||
|
// Allowed values are "SHA2" and "SHA3".
|
||||||
|
SignatureHashFamily string `protobuf:"bytes,1,opt,name=signature_hash_family,json=signatureHashFamily,proto3" json:"signature_hash_family,omitempty"`
|
||||||
|
// IdentityIdentifierHashFunction is a string representing the hash function
|
||||||
|
// to be used during the computation of the identity identifier of an MSP identity.
|
||||||
|
// Allowed values are "SHA256", "SHA384" and "SHA3_256", "SHA3_384".
|
||||||
|
IdentityIdentifierHashFunction string `protobuf:"bytes,2,opt,name=identity_identifier_hash_function,json=identityIdentifierHashFunction,proto3" json:"identity_identifier_hash_function,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricCryptoConfig) Reset() { *m = FabricCryptoConfig{} }
|
||||||
|
func (m *FabricCryptoConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*FabricCryptoConfig) ProtoMessage() {}
|
||||||
|
func (*FabricCryptoConfig) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{2}
|
||||||
|
}
|
||||||
|
func (m *FabricCryptoConfig) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_FabricCryptoConfig.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *FabricCryptoConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_FabricCryptoConfig.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *FabricCryptoConfig) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_FabricCryptoConfig.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *FabricCryptoConfig) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_FabricCryptoConfig.Size(m)
|
||||||
|
}
|
||||||
|
func (m *FabricCryptoConfig) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_FabricCryptoConfig.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_FabricCryptoConfig proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *FabricCryptoConfig) GetSignatureHashFamily() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.SignatureHashFamily
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricCryptoConfig) GetIdentityIdentifierHashFunction() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.IdentityIdentifierHashFunction
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdemixMSPConfig collects all the configuration information for
|
||||||
|
// an Idemix MSP.
|
||||||
|
type IdemixMSPConfig struct {
|
||||||
|
// Name holds the identifier of the MSP
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
// ipk represents the (serialized) issuer public key
|
||||||
|
Ipk []byte `protobuf:"bytes,2,opt,name=ipk,proto3" json:"ipk,omitempty"`
|
||||||
|
// signer may contain crypto material to configure a default signer
|
||||||
|
Signer *IdemixMSPSignerConfig `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"`
|
||||||
|
// revocation_pk is the public key used for revocation of credentials
|
||||||
|
RevocationPk []byte `protobuf:"bytes,4,opt,name=revocation_pk,json=revocationPk,proto3" json:"revocation_pk,omitempty"`
|
||||||
|
// epoch represents the current epoch (time interval) used for revocation
|
||||||
|
Epoch int64 `protobuf:"varint,5,opt,name=epoch,proto3" json:"epoch,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPConfig) Reset() { *m = IdemixMSPConfig{} }
|
||||||
|
func (m *IdemixMSPConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*IdemixMSPConfig) ProtoMessage() {}
|
||||||
|
func (*IdemixMSPConfig) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{3}
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPConfig) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_IdemixMSPConfig.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_IdemixMSPConfig.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *IdemixMSPConfig) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_IdemixMSPConfig.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPConfig) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_IdemixMSPConfig.Size(m)
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPConfig) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_IdemixMSPConfig.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_IdemixMSPConfig proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *IdemixMSPConfig) GetName() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPConfig) GetIpk() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Ipk
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPConfig) GetSigner() *IdemixMSPSignerConfig {
|
||||||
|
if m != nil {
|
||||||
|
return m.Signer
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPConfig) GetRevocationPk() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.RevocationPk
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPConfig) GetEpoch() int64 {
|
||||||
|
if m != nil {
|
||||||
|
return m.Epoch
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdemixMSPSIgnerConfig contains the crypto material to set up an idemix signing identity
|
||||||
|
type IdemixMSPSignerConfig struct {
|
||||||
|
// cred represents the serialized idemix credential of the default signer
|
||||||
|
Cred []byte `protobuf:"bytes,1,opt,name=cred,proto3" json:"cred,omitempty"`
|
||||||
|
// sk is the secret key of the default signer, corresponding to credential Cred
|
||||||
|
Sk []byte `protobuf:"bytes,2,opt,name=sk,proto3" json:"sk,omitempty"`
|
||||||
|
// organizational_unit_identifier defines the organizational unit the default signer is in
|
||||||
|
OrganizationalUnitIdentifier string `protobuf:"bytes,3,opt,name=organizational_unit_identifier,json=organizationalUnitIdentifier,proto3" json:"organizational_unit_identifier,omitempty"`
|
||||||
|
// role defines whether the default signer is admin, peer, member or client
|
||||||
|
Role int32 `protobuf:"varint,4,opt,name=role,proto3" json:"role,omitempty"`
|
||||||
|
// enrollment_id contains the enrollment id of this signer
|
||||||
|
EnrollmentId string `protobuf:"bytes,5,opt,name=enrollment_id,json=enrollmentId,proto3" json:"enrollment_id,omitempty"`
|
||||||
|
// credential_revocation_information contains a serialized CredentialRevocationInformation
|
||||||
|
CredentialRevocationInformation []byte `protobuf:"bytes,6,opt,name=credential_revocation_information,json=credentialRevocationInformation,proto3" json:"credential_revocation_information,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) Reset() { *m = IdemixMSPSignerConfig{} }
|
||||||
|
func (m *IdemixMSPSignerConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*IdemixMSPSignerConfig) ProtoMessage() {}
|
||||||
|
func (*IdemixMSPSignerConfig) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{4}
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPSignerConfig) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_IdemixMSPSignerConfig.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPSignerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_IdemixMSPSignerConfig.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *IdemixMSPSignerConfig) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_IdemixMSPSignerConfig.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPSignerConfig) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_IdemixMSPSignerConfig.Size(m)
|
||||||
|
}
|
||||||
|
func (m *IdemixMSPSignerConfig) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_IdemixMSPSignerConfig.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_IdemixMSPSignerConfig proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) GetCred() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Cred
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) GetSk() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Sk
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) GetOrganizationalUnitIdentifier() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.OrganizationalUnitIdentifier
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) GetRole() int32 {
|
||||||
|
if m != nil {
|
||||||
|
return m.Role
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) GetEnrollmentId() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.EnrollmentId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IdemixMSPSignerConfig) GetCredentialRevocationInformation() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.CredentialRevocationInformation
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SigningIdentityInfo represents the configuration information
|
||||||
|
// related to the signing identity the peer is to use for generating
|
||||||
|
// endorsements
|
||||||
|
type SigningIdentityInfo struct {
|
||||||
|
// PublicSigner carries the public information of the signing
|
||||||
|
// identity. For an X.509 provider this would be represented by
|
||||||
|
// an X.509 certificate
|
||||||
|
PublicSigner []byte `protobuf:"bytes,1,opt,name=public_signer,json=publicSigner,proto3" json:"public_signer,omitempty"`
|
||||||
|
// PrivateSigner denotes a reference to the private key of the
|
||||||
|
// peer's signing identity
|
||||||
|
PrivateSigner *KeyInfo `protobuf:"bytes,2,opt,name=private_signer,json=privateSigner,proto3" json:"private_signer,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SigningIdentityInfo) Reset() { *m = SigningIdentityInfo{} }
|
||||||
|
func (m *SigningIdentityInfo) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SigningIdentityInfo) ProtoMessage() {}
|
||||||
|
func (*SigningIdentityInfo) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{5}
|
||||||
|
}
|
||||||
|
func (m *SigningIdentityInfo) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_SigningIdentityInfo.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *SigningIdentityInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_SigningIdentityInfo.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *SigningIdentityInfo) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_SigningIdentityInfo.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *SigningIdentityInfo) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_SigningIdentityInfo.Size(m)
|
||||||
|
}
|
||||||
|
func (m *SigningIdentityInfo) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_SigningIdentityInfo.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_SigningIdentityInfo proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *SigningIdentityInfo) GetPublicSigner() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.PublicSigner
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SigningIdentityInfo) GetPrivateSigner() *KeyInfo {
|
||||||
|
if m != nil {
|
||||||
|
return m.PrivateSigner
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyInfo represents a (secret) key that is either already stored
|
||||||
|
// in the bccsp/keystore or key material to be imported to the
|
||||||
|
// bccsp key-store. In later versions it may contain also a
|
||||||
|
// keystore identifier
|
||||||
|
type KeyInfo struct {
|
||||||
|
// Identifier of the key inside the default keystore; this for
|
||||||
|
// the case of Software BCCSP as well as the HSM BCCSP would be
|
||||||
|
// the SKI of the key
|
||||||
|
KeyIdentifier string `protobuf:"bytes,1,opt,name=key_identifier,json=keyIdentifier,proto3" json:"key_identifier,omitempty"`
|
||||||
|
// KeyMaterial (optional) for the key to be imported; this is
|
||||||
|
// properly encoded key bytes, prefixed by the type of the key
|
||||||
|
KeyMaterial []byte `protobuf:"bytes,2,opt,name=key_material,json=keyMaterial,proto3" json:"key_material,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *KeyInfo) Reset() { *m = KeyInfo{} }
|
||||||
|
func (m *KeyInfo) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*KeyInfo) ProtoMessage() {}
|
||||||
|
func (*KeyInfo) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{6}
|
||||||
|
}
|
||||||
|
func (m *KeyInfo) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_KeyInfo.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *KeyInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_KeyInfo.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *KeyInfo) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_KeyInfo.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *KeyInfo) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_KeyInfo.Size(m)
|
||||||
|
}
|
||||||
|
func (m *KeyInfo) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_KeyInfo.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_KeyInfo proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *KeyInfo) GetKeyIdentifier() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.KeyIdentifier
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *KeyInfo) GetKeyMaterial() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.KeyMaterial
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricOUIdentifier represents an organizational unit and
|
||||||
|
// its related chain of trust identifier.
|
||||||
|
type FabricOUIdentifier struct {
|
||||||
|
// Certificate represents the second certificate in a certification chain.
|
||||||
|
// (Notice that the first certificate in a certification chain is supposed
|
||||||
|
// to be the certificate of an identity).
|
||||||
|
// It must correspond to the certificate of root or intermediate CA
|
||||||
|
// recognized by the MSP this message belongs to.
|
||||||
|
// Starting from this certificate, a certification chain is computed
|
||||||
|
// and bound to the OrganizationUnitIdentifier specified
|
||||||
|
Certificate []byte `protobuf:"bytes,1,opt,name=certificate,proto3" json:"certificate,omitempty"`
|
||||||
|
// OrganizationUnitIdentifier defines the organizational unit under the
|
||||||
|
// MSP identified with MSPIdentifier
|
||||||
|
OrganizationalUnitIdentifier string `protobuf:"bytes,2,opt,name=organizational_unit_identifier,json=organizationalUnitIdentifier,proto3" json:"organizational_unit_identifier,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricOUIdentifier) Reset() { *m = FabricOUIdentifier{} }
|
||||||
|
func (m *FabricOUIdentifier) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*FabricOUIdentifier) ProtoMessage() {}
|
||||||
|
func (*FabricOUIdentifier) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{7}
|
||||||
|
}
|
||||||
|
func (m *FabricOUIdentifier) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_FabricOUIdentifier.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *FabricOUIdentifier) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_FabricOUIdentifier.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *FabricOUIdentifier) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_FabricOUIdentifier.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *FabricOUIdentifier) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_FabricOUIdentifier.Size(m)
|
||||||
|
}
|
||||||
|
func (m *FabricOUIdentifier) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_FabricOUIdentifier.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_FabricOUIdentifier proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *FabricOUIdentifier) GetCertificate() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Certificate
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricOUIdentifier) GetOrganizationalUnitIdentifier() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.OrganizationalUnitIdentifier
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricNodeOUs contains configuration to tell apart clients from peers from orderers
|
||||||
|
// based on OUs. If NodeOUs recognition is enabled then an msp identity
|
||||||
|
// that does not contain any of the specified OU will be considered invalid.
|
||||||
|
type FabricNodeOUs struct {
|
||||||
|
// If true then an msp identity that does not contain any of the specified OU will be considered invalid.
|
||||||
|
Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
|
||||||
|
// OU Identifier of the clients
|
||||||
|
ClientOuIdentifier *FabricOUIdentifier `protobuf:"bytes,2,opt,name=client_ou_identifier,json=clientOuIdentifier,proto3" json:"client_ou_identifier,omitempty"`
|
||||||
|
// OU Identifier of the peers
|
||||||
|
PeerOuIdentifier *FabricOUIdentifier `protobuf:"bytes,3,opt,name=peer_ou_identifier,json=peerOuIdentifier,proto3" json:"peer_ou_identifier,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricNodeOUs) Reset() { *m = FabricNodeOUs{} }
|
||||||
|
func (m *FabricNodeOUs) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*FabricNodeOUs) ProtoMessage() {}
|
||||||
|
func (*FabricNodeOUs) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_config_e749e5bd1d6d997b, []int{8}
|
||||||
|
}
|
||||||
|
func (m *FabricNodeOUs) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_FabricNodeOUs.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *FabricNodeOUs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_FabricNodeOUs.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *FabricNodeOUs) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_FabricNodeOUs.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *FabricNodeOUs) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_FabricNodeOUs.Size(m)
|
||||||
|
}
|
||||||
|
func (m *FabricNodeOUs) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_FabricNodeOUs.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_FabricNodeOUs proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *FabricNodeOUs) GetEnable() bool {
|
||||||
|
if m != nil {
|
||||||
|
return m.Enable
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricNodeOUs) GetClientOuIdentifier() *FabricOUIdentifier {
|
||||||
|
if m != nil {
|
||||||
|
return m.ClientOuIdentifier
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FabricNodeOUs) GetPeerOuIdentifier() *FabricOUIdentifier {
|
||||||
|
if m != nil {
|
||||||
|
return m.PeerOuIdentifier
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*MSPConfig)(nil), "msp.MSPConfig")
|
||||||
|
proto.RegisterType((*FabricMSPConfig)(nil), "msp.FabricMSPConfig")
|
||||||
|
proto.RegisterType((*FabricCryptoConfig)(nil), "msp.FabricCryptoConfig")
|
||||||
|
proto.RegisterType((*IdemixMSPConfig)(nil), "msp.IdemixMSPConfig")
|
||||||
|
proto.RegisterType((*IdemixMSPSignerConfig)(nil), "msp.IdemixMSPSignerConfig")
|
||||||
|
proto.RegisterType((*SigningIdentityInfo)(nil), "msp.SigningIdentityInfo")
|
||||||
|
proto.RegisterType((*KeyInfo)(nil), "msp.KeyInfo")
|
||||||
|
proto.RegisterType((*FabricOUIdentifier)(nil), "msp.FabricOUIdentifier")
|
||||||
|
proto.RegisterType((*FabricNodeOUs)(nil), "msp.FabricNodeOUs")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("msp/msp_config.proto", fileDescriptor_msp_config_e749e5bd1d6d997b) }
|
||||||
|
|
||||||
|
var fileDescriptor_msp_config_e749e5bd1d6d997b = []byte{
|
||||||
|
// 847 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x5f, 0x6f, 0xe3, 0x44,
|
||||||
|
0x10, 0x57, 0x92, 0x26, 0x77, 0x99, 0x38, 0x49, 0xd9, 0xeb, 0x15, 0x0b, 0x71, 0x77, 0xa9, 0x01,
|
||||||
|
0x91, 0x17, 0x52, 0xa9, 0x87, 0x84, 0x84, 0x78, 0xba, 0xc2, 0x09, 0x03, 0xa5, 0xd5, 0x56, 0x7d,
|
||||||
|
0xe1, 0xc5, 0xda, 0xd8, 0x9b, 0x64, 0x65, 0x7b, 0xd7, 0xda, 0x5d, 0x9f, 0x08, 0xe2, 0x99, 0x2f,
|
||||||
|
0xc0, 0x77, 0xe0, 0x99, 0x57, 0xbe, 0x1d, 0xda, 0x3f, 0x8d, 0x9d, 0x6b, 0x15, 0x78, 0x9b, 0x9d,
|
||||||
|
0xf9, 0xcd, 0xcf, 0xb3, 0xbf, 0x99, 0x59, 0xc3, 0x49, 0xa9, 0xaa, 0xf3, 0x52, 0x55, 0x49, 0x2a,
|
||||||
|
0xf8, 0x8a, 0xad, 0x17, 0x95, 0x14, 0x5a, 0xa0, 0x5e, 0xa9, 0xaa, 0xe8, 0x2b, 0x18, 0x5e, 0xdd,
|
||||||
|
0xde, 0x5c, 0x5a, 0x3f, 0x42, 0x70, 0xa4, 0xb7, 0x15, 0x0d, 0x3b, 0xb3, 0xce, 0xbc, 0x8f, 0xad,
|
||||||
|
0x8d, 0x4e, 0x61, 0xe0, 0xb2, 0xc2, 0xee, 0xac, 0x33, 0x0f, 0xb0, 0x3f, 0x45, 0x7f, 0x1f, 0xc1,
|
||||||
|
0xf4, 0x2d, 0x59, 0x4a, 0x96, 0xee, 0xe5, 0x73, 0x52, 0xba, 0xfc, 0x21, 0xb6, 0x36, 0x7a, 0x01,
|
||||||
|
0x20, 0x85, 0xd0, 0x49, 0x4a, 0xa5, 0x56, 0x61, 0x77, 0xd6, 0x9b, 0x07, 0x78, 0x68, 0x3c, 0x97,
|
||||||
|
0xc6, 0x81, 0xbe, 0x00, 0xc4, 0xb8, 0xa6, 0xb2, 0xa4, 0x19, 0x23, 0x9a, 0x7a, 0x58, 0xcf, 0xc2,
|
||||||
|
0x3e, 0x68, 0x47, 0x1c, 0xfc, 0x14, 0x06, 0x24, 0x2b, 0x19, 0x57, 0xe1, 0x91, 0x85, 0xf8, 0x13,
|
||||||
|
0xfa, 0x1c, 0xa6, 0x92, 0xbe, 0x13, 0x29, 0xd1, 0x4c, 0xf0, 0xa4, 0x60, 0x4a, 0x87, 0x7d, 0x0b,
|
||||||
|
0x98, 0x34, 0xee, 0x9f, 0x98, 0xd2, 0xe8, 0x12, 0x8e, 0x15, 0x5b, 0x73, 0xc6, 0xd7, 0x09, 0xcb,
|
||||||
|
0x28, 0xd7, 0x4c, 0x6f, 0xc3, 0xc1, 0xac, 0x33, 0x1f, 0x5d, 0x84, 0x8b, 0x52, 0x55, 0x8b, 0x5b,
|
||||||
|
0x17, 0x8c, 0x7d, 0x2c, 0xe6, 0x2b, 0x81, 0xa7, 0x6a, 0xdf, 0x89, 0x12, 0x78, 0x25, 0xe4, 0x9a,
|
||||||
|
0x70, 0xf6, 0x9b, 0x25, 0x26, 0x45, 0x52, 0x73, 0xa6, 0x3d, 0xe1, 0x8a, 0x51, 0xa9, 0xc2, 0x27,
|
||||||
|
0xb3, 0xde, 0x7c, 0x74, 0xf1, 0xa1, 0xe5, 0x74, 0x32, 0x5d, 0xdf, 0xc5, 0xbb, 0x38, 0x7e, 0xb1,
|
||||||
|
0x9f, 0x7f, 0xc7, 0x99, 0x6e, 0xa2, 0x0a, 0x7d, 0x03, 0xe3, 0x54, 0x6e, 0x2b, 0x2d, 0x7c, 0xc7,
|
||||||
|
0xc2, 0xa7, 0xb6, 0xc4, 0x36, 0xdd, 0xa5, 0x8d, 0x3b, 0xe1, 0x71, 0x90, 0xb6, 0x4e, 0xe8, 0x53,
|
||||||
|
0x98, 0xe8, 0x42, 0x25, 0x2d, 0xd9, 0x87, 0x56, 0x8b, 0x40, 0x17, 0x0a, 0xef, 0x94, 0xff, 0x12,
|
||||||
|
0x4e, 0x0d, 0xea, 0x11, 0xf5, 0xc1, 0xa2, 0x4f, 0x74, 0xa1, 0xe2, 0x07, 0x0d, 0xf8, 0x1a, 0xa6,
|
||||||
|
0x2b, 0xfb, 0xfd, 0x84, 0x8b, 0x8c, 0x26, 0xa2, 0x56, 0xe1, 0xc8, 0xd6, 0x86, 0x5a, 0xb5, 0xfd,
|
||||||
|
0x2c, 0x32, 0x7a, 0x7d, 0xa7, 0xf0, 0x78, 0xd5, 0x1c, 0x6b, 0x15, 0xfd, 0xd9, 0x01, 0xf4, 0xb0,
|
||||||
|
0x78, 0x74, 0x01, 0xcf, 0x8d, 0xc0, 0x44, 0xd7, 0x92, 0x26, 0x1b, 0xa2, 0x36, 0xc9, 0x8a, 0x94,
|
||||||
|
0xac, 0xd8, 0xfa, 0x31, 0x7a, 0xb6, 0x0b, 0x7e, 0x4f, 0xd4, 0xe6, 0xad, 0x0d, 0xa1, 0x18, 0xce,
|
||||||
|
0xee, 0xdb, 0xd7, 0x92, 0xdd, 0x67, 0xd7, 0x3c, 0x35, 0xb2, 0xda, 0x81, 0x1d, 0xe2, 0x97, 0xf7,
|
||||||
|
0xc0, 0x46, 0x60, 0x4b, 0xe4, 0x51, 0xd1, 0x5f, 0x1d, 0x98, 0xc6, 0x19, 0x2d, 0xd9, 0xaf, 0x87,
|
||||||
|
0x07, 0xf9, 0x18, 0x7a, 0xac, 0xca, 0xfd, 0x16, 0x18, 0x13, 0x5d, 0xc0, 0xc0, 0xd4, 0x46, 0x65,
|
||||||
|
0xd8, 0xb3, 0x12, 0x7c, 0x64, 0x25, 0xd8, 0x71, 0xdd, 0xda, 0x98, 0xef, 0x90, 0x47, 0xa2, 0x4f,
|
||||||
|
0x60, 0xdc, 0x1a, 0xd4, 0x2a, 0x0f, 0x8f, 0x2c, 0x5f, 0xd0, 0x38, 0x6f, 0x72, 0x74, 0x02, 0x7d,
|
||||||
|
0x5a, 0x89, 0x74, 0x13, 0xf6, 0x67, 0x9d, 0x79, 0x0f, 0xbb, 0x43, 0xf4, 0x47, 0x17, 0x9e, 0x3f,
|
||||||
|
0x4a, 0x6e, 0xca, 0x4d, 0x25, 0xcd, 0x6c, 0xb9, 0x01, 0xb6, 0x36, 0x9a, 0x40, 0x57, 0xdd, 0x57,
|
||||||
|
0xdb, 0x55, 0x39, 0xfa, 0x16, 0x5e, 0x1e, 0x9e, 0x59, 0x7b, 0x89, 0x21, 0xfe, 0xf8, 0xd0, 0x64,
|
||||||
|
0x9a, 0x2f, 0x49, 0x51, 0x50, 0x5b, 0x75, 0x1f, 0x5b, 0xdb, 0x5c, 0x89, 0x72, 0x29, 0x8a, 0xa2,
|
||||||
|
0xa4, 0xdc, 0x10, 0xda, 0xaa, 0x87, 0x38, 0x68, 0x9c, 0x71, 0x86, 0x7e, 0x80, 0x33, 0x53, 0x96,
|
||||||
|
0x21, 0x22, 0x45, 0xd2, 0x92, 0x80, 0xf1, 0x95, 0x90, 0xa5, 0xb5, 0xed, 0x22, 0x06, 0xf8, 0x55,
|
||||||
|
0x03, 0xc4, 0x3b, 0x5c, 0xdc, 0xc0, 0x22, 0x01, 0xcf, 0x1e, 0x59, 0x53, 0x53, 0x47, 0x55, 0x2f,
|
||||||
|
0x0b, 0x96, 0x26, 0xbe, 0x2b, 0x4e, 0x8e, 0xc0, 0x39, 0x9d, 0x60, 0xe8, 0x35, 0x4c, 0x2a, 0xc9,
|
||||||
|
0xde, 0x99, 0x61, 0xf7, 0xa8, 0xae, 0xed, 0x5d, 0x60, 0x7b, 0xf7, 0x23, 0x75, 0x1b, 0x3f, 0xf6,
|
||||||
|
0x18, 0x97, 0x14, 0xdd, 0xc2, 0x13, 0x1f, 0x41, 0x9f, 0xc1, 0x24, 0xa7, 0xed, 0x99, 0xf3, 0x33,
|
||||||
|
0x32, 0xce, 0x69, 0x6b, 0xc0, 0xd0, 0x19, 0x04, 0x06, 0x56, 0x12, 0x4d, 0x25, 0x23, 0x85, 0xef,
|
||||||
|
0xc3, 0x28, 0xa7, 0xdb, 0x2b, 0xef, 0x8a, 0x7e, 0xbf, 0x5f, 0x86, 0xf6, 0xc3, 0x80, 0x66, 0x30,
|
||||||
|
0x32, 0x4b, 0xc8, 0x56, 0x2c, 0x25, 0x9a, 0xfa, 0x2b, 0xb4, 0x5d, 0xff, 0xa3, 0x91, 0xdd, 0xff,
|
||||||
|
0x6e, 0x64, 0xf4, 0x4f, 0x07, 0xc6, 0x7b, 0xcb, 0x6a, 0x9e, 0x56, 0xca, 0xc9, 0xb2, 0x70, 0x1f,
|
||||||
|
0x7d, 0x8a, 0xfd, 0x09, 0xc5, 0x70, 0x92, 0x16, 0xcc, 0xb4, 0x56, 0xd4, 0xef, 0x7f, 0xe5, 0xc0,
|
||||||
|
0x0b, 0x87, 0x5c, 0xd2, 0x75, 0xdd, 0xba, 0xdc, 0x77, 0x80, 0x2a, 0x4a, 0xe5, 0x7b, 0x44, 0xbd,
|
||||||
|
0xc3, 0x44, 0xc7, 0x26, 0xa5, 0x4d, 0xf3, 0x26, 0x81, 0x33, 0x21, 0xd7, 0x8b, 0xcd, 0xb6, 0xa2,
|
||||||
|
0xb2, 0xa0, 0xd9, 0x9a, 0xca, 0x85, 0x7b, 0x68, 0xdc, 0x8f, 0x4d, 0x19, 0xa6, 0x37, 0xc7, 0x57,
|
||||||
|
0xaa, 0x72, 0xeb, 0x71, 0x43, 0xd2, 0x9c, 0xac, 0xe9, 0x2f, 0xf3, 0x35, 0xd3, 0x9b, 0x7a, 0xb9,
|
||||||
|
0x48, 0x45, 0x79, 0xde, 0xca, 0x3d, 0x77, 0xb9, 0xe7, 0x2e, 0xd7, 0xfc, 0x26, 0x97, 0x03, 0x6b,
|
||||||
|
0xbf, 0xfe, 0x37, 0x00, 0x00, 0xff, 0xff, 0x54, 0x67, 0x46, 0xdb, 0x38, 0x07, 0x00, 0x00,
|
||||||
|
}
|
||||||
208
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_config.proto
generated
vendored
Normal file
208
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_config.proto
generated
vendored
Normal file
|
|
@ -0,0 +1,208 @@
|
||||||
|
/*
|
||||||
|
Copyright IBM Corp. All Rights Reserved.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option go_package = "github.com/hyperledger/fabric/protos/msp";
|
||||||
|
option java_package = "org.hyperledger.fabric.protos.msp";
|
||||||
|
option java_outer_classname = "MspConfigPackage";
|
||||||
|
|
||||||
|
package msp;
|
||||||
|
|
||||||
|
// MSPConfig collects all the configuration information for
|
||||||
|
// an MSP. The Config field should be unmarshalled in a way
|
||||||
|
// that depends on the Type
|
||||||
|
message MSPConfig {
|
||||||
|
// Type holds the type of the MSP; the default one would
|
||||||
|
// be of type FABRIC implementing an X.509 based provider
|
||||||
|
int32 type = 1;
|
||||||
|
|
||||||
|
// Config is MSP dependent configuration info
|
||||||
|
bytes config = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricMSPConfig collects all the configuration information for
|
||||||
|
// a Fabric MSP.
|
||||||
|
// Here we assume a default certificate validation policy, where
|
||||||
|
// any certificate signed by any of the listed rootCA certs would
|
||||||
|
// be considered as valid under this MSP.
|
||||||
|
// This MSP may or may not come with a signing identity. If it does,
|
||||||
|
// it can also issue signing identities. If it does not, it can only
|
||||||
|
// be used to validate and verify certificates.
|
||||||
|
message FabricMSPConfig {
|
||||||
|
// Name holds the identifier of the MSP; MSP identifier
|
||||||
|
// is chosen by the application that governs this MSP.
|
||||||
|
// For example, and assuming the default implementation of MSP,
|
||||||
|
// that is X.509-based and considers a single Issuer,
|
||||||
|
// this can refer to the Subject OU field or the Issuer OU field.
|
||||||
|
string name = 1;
|
||||||
|
|
||||||
|
// List of root certificates trusted by this MSP
|
||||||
|
// they are used upon certificate validation (see
|
||||||
|
// comment for IntermediateCerts below)
|
||||||
|
repeated bytes root_certs = 2;
|
||||||
|
|
||||||
|
// List of intermediate certificates trusted by this MSP;
|
||||||
|
// they are used upon certificate validation as follows:
|
||||||
|
// validation attempts to build a path from the certificate
|
||||||
|
// to be validated (which is at one end of the path) and
|
||||||
|
// one of the certs in the RootCerts field (which is at
|
||||||
|
// the other end of the path). If the path is longer than
|
||||||
|
// 2, certificates in the middle are searched within the
|
||||||
|
// IntermediateCerts pool
|
||||||
|
repeated bytes intermediate_certs = 3;
|
||||||
|
|
||||||
|
// Identity denoting the administrator of this MSP
|
||||||
|
repeated bytes admins = 4;
|
||||||
|
|
||||||
|
// Identity revocation list
|
||||||
|
repeated bytes revocation_list = 5;
|
||||||
|
|
||||||
|
// SigningIdentity holds information on the signing identity
|
||||||
|
// this peer is to use, and which is to be imported by the
|
||||||
|
// MSP defined before
|
||||||
|
SigningIdentityInfo signing_identity = 6;
|
||||||
|
|
||||||
|
// OrganizationalUnitIdentifiers holds one or more
|
||||||
|
// fabric organizational unit identifiers that belong to
|
||||||
|
// this MSP configuration
|
||||||
|
repeated FabricOUIdentifier organizational_unit_identifiers = 7;
|
||||||
|
|
||||||
|
// FabricCryptoConfig contains the configuration parameters
|
||||||
|
// for the cryptographic algorithms used by this MSP
|
||||||
|
FabricCryptoConfig crypto_config = 8;
|
||||||
|
|
||||||
|
// List of TLS root certificates trusted by this MSP.
|
||||||
|
// They are returned by GetTLSRootCerts.
|
||||||
|
repeated bytes tls_root_certs = 9;
|
||||||
|
|
||||||
|
// List of TLS intermediate certificates trusted by this MSP;
|
||||||
|
// They are returned by GetTLSIntermediateCerts.
|
||||||
|
repeated bytes tls_intermediate_certs = 10;
|
||||||
|
|
||||||
|
// fabric_node_ous contains the configuration to distinguish clients from peers from orderers
|
||||||
|
// based on the OUs.
|
||||||
|
FabricNodeOUs fabric_node_ous = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricCryptoConfig contains configuration parameters
|
||||||
|
// for the cryptographic algorithms used by the MSP
|
||||||
|
// this configuration refers to
|
||||||
|
message FabricCryptoConfig {
|
||||||
|
|
||||||
|
// SignatureHashFamily is a string representing the hash family to be used
|
||||||
|
// during sign and verify operations.
|
||||||
|
// Allowed values are "SHA2" and "SHA3".
|
||||||
|
string signature_hash_family = 1;
|
||||||
|
|
||||||
|
// IdentityIdentifierHashFunction is a string representing the hash function
|
||||||
|
// to be used during the computation of the identity identifier of an MSP identity.
|
||||||
|
// Allowed values are "SHA256", "SHA384" and "SHA3_256", "SHA3_384".
|
||||||
|
string identity_identifier_hash_function = 2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdemixMSPConfig collects all the configuration information for
|
||||||
|
// an Idemix MSP.
|
||||||
|
message IdemixMSPConfig {
|
||||||
|
// Name holds the identifier of the MSP
|
||||||
|
string name = 1;
|
||||||
|
|
||||||
|
// ipk represents the (serialized) issuer public key
|
||||||
|
bytes ipk = 2;
|
||||||
|
|
||||||
|
// signer may contain crypto material to configure a default signer
|
||||||
|
IdemixMSPSignerConfig signer = 3;
|
||||||
|
|
||||||
|
// revocation_pk is the public key used for revocation of credentials
|
||||||
|
bytes revocation_pk = 4;
|
||||||
|
|
||||||
|
// epoch represents the current epoch (time interval) used for revocation
|
||||||
|
int64 epoch = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdemixMSPSIgnerConfig contains the crypto material to set up an idemix signing identity
|
||||||
|
message IdemixMSPSignerConfig {
|
||||||
|
// cred represents the serialized idemix credential of the default signer
|
||||||
|
bytes cred = 1;
|
||||||
|
|
||||||
|
// sk is the secret key of the default signer, corresponding to credential Cred
|
||||||
|
bytes sk = 2;
|
||||||
|
|
||||||
|
// organizational_unit_identifier defines the organizational unit the default signer is in
|
||||||
|
string organizational_unit_identifier = 3;
|
||||||
|
|
||||||
|
// role defines whether the default signer is admin, peer, member or client
|
||||||
|
int32 role = 4;
|
||||||
|
|
||||||
|
// enrollment_id contains the enrollment id of this signer
|
||||||
|
string enrollment_id = 5;
|
||||||
|
|
||||||
|
// credential_revocation_information contains a serialized CredentialRevocationInformation
|
||||||
|
bytes credential_revocation_information = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SigningIdentityInfo represents the configuration information
|
||||||
|
// related to the signing identity the peer is to use for generating
|
||||||
|
// endorsements
|
||||||
|
message SigningIdentityInfo {
|
||||||
|
// PublicSigner carries the public information of the signing
|
||||||
|
// identity. For an X.509 provider this would be represented by
|
||||||
|
// an X.509 certificate
|
||||||
|
bytes public_signer = 1;
|
||||||
|
|
||||||
|
// PrivateSigner denotes a reference to the private key of the
|
||||||
|
// peer's signing identity
|
||||||
|
KeyInfo private_signer = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyInfo represents a (secret) key that is either already stored
|
||||||
|
// in the bccsp/keystore or key material to be imported to the
|
||||||
|
// bccsp key-store. In later versions it may contain also a
|
||||||
|
// keystore identifier
|
||||||
|
message KeyInfo {
|
||||||
|
// Identifier of the key inside the default keystore; this for
|
||||||
|
// the case of Software BCCSP as well as the HSM BCCSP would be
|
||||||
|
// the SKI of the key
|
||||||
|
string key_identifier = 1;
|
||||||
|
|
||||||
|
// KeyMaterial (optional) for the key to be imported; this is
|
||||||
|
// properly encoded key bytes, prefixed by the type of the key
|
||||||
|
bytes key_material = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricOUIdentifier represents an organizational unit and
|
||||||
|
// its related chain of trust identifier.
|
||||||
|
message FabricOUIdentifier {
|
||||||
|
|
||||||
|
// Certificate represents the second certificate in a certification chain.
|
||||||
|
// (Notice that the first certificate in a certification chain is supposed
|
||||||
|
// to be the certificate of an identity).
|
||||||
|
// It must correspond to the certificate of root or intermediate CA
|
||||||
|
// recognized by the MSP this message belongs to.
|
||||||
|
// Starting from this certificate, a certification chain is computed
|
||||||
|
// and bound to the OrganizationUnitIdentifier specified
|
||||||
|
bytes certificate = 1;
|
||||||
|
|
||||||
|
// OrganizationUnitIdentifier defines the organizational unit under the
|
||||||
|
// MSP identified with MSPIdentifier
|
||||||
|
string organizational_unit_identifier = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FabricNodeOUs contains configuration to tell apart clients from peers from orderers
|
||||||
|
// based on OUs. If NodeOUs recognition is enabled then an msp identity
|
||||||
|
// that does not contain any of the specified OU will be considered invalid.
|
||||||
|
message FabricNodeOUs {
|
||||||
|
// If true then an msp identity that does not contain any of the specified OU will be considered invalid.
|
||||||
|
bool enable = 1;
|
||||||
|
|
||||||
|
// OU Identifier of the clients
|
||||||
|
FabricOUIdentifier client_ou_identifier = 2;
|
||||||
|
|
||||||
|
// OU Identifier of the peers
|
||||||
|
FabricOUIdentifier peer_ou_identifier = 3;
|
||||||
|
|
||||||
|
}
|
||||||
43
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_principal.go
generated
vendored
Normal file
43
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_principal.go
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
Copyright IBM Corp. 2017 All Rights Reserved.
|
||||||
|
|
||||||
|
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 msp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (mp *MSPPrincipal) VariablyOpaqueFields() []string {
|
||||||
|
return []string{"principal"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *MSPPrincipal) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
|
||||||
|
if name != mp.VariablyOpaqueFields()[0] {
|
||||||
|
return nil, fmt.Errorf("not a marshaled field: %s", name)
|
||||||
|
}
|
||||||
|
switch mp.PrincipalClassification {
|
||||||
|
case MSPPrincipal_ROLE:
|
||||||
|
return &MSPRole{}, nil
|
||||||
|
case MSPPrincipal_ORGANIZATION_UNIT:
|
||||||
|
return &OrganizationUnit{}, nil
|
||||||
|
case MSPPrincipal_IDENTITY:
|
||||||
|
return nil, fmt.Errorf("unable to decode MSP type IDENTITY until the protos are fixed to include the IDENTITY proto in protos/msp")
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unable to decode MSP type: %v", mp.PrincipalClassification)
|
||||||
|
}
|
||||||
|
}
|
||||||
437
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_principal.pb.go
generated
vendored
Normal file
437
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_principal.pb.go
generated
vendored
Normal file
|
|
@ -0,0 +1,437 @@
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// source: msp/msp_principal.proto
|
||||||
|
|
||||||
|
package msp // import "github.com/hyperledger/fabric/protos/msp"
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
type MSPPrincipal_Classification int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
MSPPrincipal_ROLE MSPPrincipal_Classification = 0
|
||||||
|
// one of a member of MSP network, and the one of an
|
||||||
|
// administrator of an MSP network
|
||||||
|
MSPPrincipal_ORGANIZATION_UNIT MSPPrincipal_Classification = 1
|
||||||
|
// groupping of entities, per MSP affiliation
|
||||||
|
// E.g., this can well be represented by an MSP's
|
||||||
|
// Organization unit
|
||||||
|
MSPPrincipal_IDENTITY MSPPrincipal_Classification = 2
|
||||||
|
// identity
|
||||||
|
MSPPrincipal_ANONYMITY MSPPrincipal_Classification = 3
|
||||||
|
// an identity to be anonymous or nominal.
|
||||||
|
MSPPrincipal_COMBINED MSPPrincipal_Classification = 4
|
||||||
|
)
|
||||||
|
|
||||||
|
var MSPPrincipal_Classification_name = map[int32]string{
|
||||||
|
0: "ROLE",
|
||||||
|
1: "ORGANIZATION_UNIT",
|
||||||
|
2: "IDENTITY",
|
||||||
|
3: "ANONYMITY",
|
||||||
|
4: "COMBINED",
|
||||||
|
}
|
||||||
|
var MSPPrincipal_Classification_value = map[string]int32{
|
||||||
|
"ROLE": 0,
|
||||||
|
"ORGANIZATION_UNIT": 1,
|
||||||
|
"IDENTITY": 2,
|
||||||
|
"ANONYMITY": 3,
|
||||||
|
"COMBINED": 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x MSPPrincipal_Classification) String() string {
|
||||||
|
return proto.EnumName(MSPPrincipal_Classification_name, int32(x))
|
||||||
|
}
|
||||||
|
func (MSPPrincipal_Classification) EnumDescriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{0, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MSPRole_MSPRoleType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
MSPRole_MEMBER MSPRole_MSPRoleType = 0
|
||||||
|
MSPRole_ADMIN MSPRole_MSPRoleType = 1
|
||||||
|
MSPRole_CLIENT MSPRole_MSPRoleType = 2
|
||||||
|
MSPRole_PEER MSPRole_MSPRoleType = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
var MSPRole_MSPRoleType_name = map[int32]string{
|
||||||
|
0: "MEMBER",
|
||||||
|
1: "ADMIN",
|
||||||
|
2: "CLIENT",
|
||||||
|
3: "PEER",
|
||||||
|
}
|
||||||
|
var MSPRole_MSPRoleType_value = map[string]int32{
|
||||||
|
"MEMBER": 0,
|
||||||
|
"ADMIN": 1,
|
||||||
|
"CLIENT": 2,
|
||||||
|
"PEER": 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x MSPRole_MSPRoleType) String() string {
|
||||||
|
return proto.EnumName(MSPRole_MSPRoleType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (MSPRole_MSPRoleType) EnumDescriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{2, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MSPIdentityAnonymity_MSPIdentityAnonymityType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
MSPIdentityAnonymity_NOMINAL MSPIdentityAnonymity_MSPIdentityAnonymityType = 0
|
||||||
|
MSPIdentityAnonymity_ANONYMOUS MSPIdentityAnonymity_MSPIdentityAnonymityType = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
var MSPIdentityAnonymity_MSPIdentityAnonymityType_name = map[int32]string{
|
||||||
|
0: "NOMINAL",
|
||||||
|
1: "ANONYMOUS",
|
||||||
|
}
|
||||||
|
var MSPIdentityAnonymity_MSPIdentityAnonymityType_value = map[string]int32{
|
||||||
|
"NOMINAL": 0,
|
||||||
|
"ANONYMOUS": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x MSPIdentityAnonymity_MSPIdentityAnonymityType) String() string {
|
||||||
|
return proto.EnumName(MSPIdentityAnonymity_MSPIdentityAnonymityType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (MSPIdentityAnonymity_MSPIdentityAnonymityType) EnumDescriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{3, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSPPrincipal aims to represent an MSP-centric set of identities.
|
||||||
|
// In particular, this structure allows for definition of
|
||||||
|
// - a group of identities that are member of the same MSP
|
||||||
|
// - a group of identities that are member of the same organization unit
|
||||||
|
// in the same MSP
|
||||||
|
// - a group of identities that are administering a specific MSP
|
||||||
|
// - a specific identity
|
||||||
|
// Expressing these groups is done given two fields of the fields below
|
||||||
|
// - Classification, that defines the type of classification of identities
|
||||||
|
// in an MSP this principal would be defined on; Classification can take
|
||||||
|
// three values:
|
||||||
|
// (i) ByMSPRole: that represents a classification of identities within
|
||||||
|
// MSP based on one of the two pre-defined MSP rules, "member" and "admin"
|
||||||
|
// (ii) ByOrganizationUnit: that represents a classification of identities
|
||||||
|
// within MSP based on the organization unit an identity belongs to
|
||||||
|
// (iii)ByIdentity that denotes that MSPPrincipal is mapped to a single
|
||||||
|
// identity/certificate; this would mean that the Principal bytes
|
||||||
|
// message
|
||||||
|
type MSPPrincipal struct {
|
||||||
|
// Classification describes the way that one should process
|
||||||
|
// Principal. An Classification value of "ByOrganizationUnit" reflects
|
||||||
|
// that "Principal" contains the name of an organization this MSP
|
||||||
|
// handles. A Classification value "ByIdentity" means that
|
||||||
|
// "Principal" contains a specific identity. Default value
|
||||||
|
// denotes that Principal contains one of the groups by
|
||||||
|
// default supported by all MSPs ("admin" or "member").
|
||||||
|
PrincipalClassification MSPPrincipal_Classification `protobuf:"varint,1,opt,name=principal_classification,json=principalClassification,proto3,enum=common.MSPPrincipal_Classification" json:"principal_classification,omitempty"`
|
||||||
|
// Principal completes the policy principal definition. For the default
|
||||||
|
// principal types, Principal can be either "Admin" or "Member".
|
||||||
|
// For the ByOrganizationUnit/ByIdentity values of Classification,
|
||||||
|
// PolicyPrincipal acquires its value from an organization unit or
|
||||||
|
// identity, respectively.
|
||||||
|
// For the Combined Classification type, the Principal is a marshalled
|
||||||
|
// CombinedPrincipal.
|
||||||
|
Principal []byte `protobuf:"bytes,2,opt,name=principal,proto3" json:"principal,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPPrincipal) Reset() { *m = MSPPrincipal{} }
|
||||||
|
func (m *MSPPrincipal) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*MSPPrincipal) ProtoMessage() {}
|
||||||
|
func (*MSPPrincipal) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{0}
|
||||||
|
}
|
||||||
|
func (m *MSPPrincipal) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_MSPPrincipal.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *MSPPrincipal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_MSPPrincipal.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *MSPPrincipal) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_MSPPrincipal.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *MSPPrincipal) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_MSPPrincipal.Size(m)
|
||||||
|
}
|
||||||
|
func (m *MSPPrincipal) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_MSPPrincipal.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_MSPPrincipal proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *MSPPrincipal) GetPrincipalClassification() MSPPrincipal_Classification {
|
||||||
|
if m != nil {
|
||||||
|
return m.PrincipalClassification
|
||||||
|
}
|
||||||
|
return MSPPrincipal_ROLE
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPPrincipal) GetPrincipal() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Principal
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrganizationUnit governs the organization of the Principal
|
||||||
|
// field of a policy principal when a specific organization unity members
|
||||||
|
// are to be defined within a policy principal.
|
||||||
|
type OrganizationUnit struct {
|
||||||
|
// MSPIdentifier represents the identifier of the MSP this organization unit
|
||||||
|
// refers to
|
||||||
|
MspIdentifier string `protobuf:"bytes,1,opt,name=msp_identifier,json=mspIdentifier,proto3" json:"msp_identifier,omitempty"`
|
||||||
|
// OrganizationUnitIdentifier defines the organizational unit under the
|
||||||
|
// MSP identified with MSPIdentifier
|
||||||
|
OrganizationalUnitIdentifier string `protobuf:"bytes,2,opt,name=organizational_unit_identifier,json=organizationalUnitIdentifier,proto3" json:"organizational_unit_identifier,omitempty"`
|
||||||
|
// CertifiersIdentifier is the hash of certificates chain of trust
|
||||||
|
// related to this organizational unit
|
||||||
|
CertifiersIdentifier []byte `protobuf:"bytes,3,opt,name=certifiers_identifier,json=certifiersIdentifier,proto3" json:"certifiers_identifier,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *OrganizationUnit) Reset() { *m = OrganizationUnit{} }
|
||||||
|
func (m *OrganizationUnit) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*OrganizationUnit) ProtoMessage() {}
|
||||||
|
func (*OrganizationUnit) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{1}
|
||||||
|
}
|
||||||
|
func (m *OrganizationUnit) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_OrganizationUnit.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *OrganizationUnit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_OrganizationUnit.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *OrganizationUnit) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_OrganizationUnit.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *OrganizationUnit) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_OrganizationUnit.Size(m)
|
||||||
|
}
|
||||||
|
func (m *OrganizationUnit) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_OrganizationUnit.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_OrganizationUnit proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *OrganizationUnit) GetMspIdentifier() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.MspIdentifier
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *OrganizationUnit) GetOrganizationalUnitIdentifier() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.OrganizationalUnitIdentifier
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *OrganizationUnit) GetCertifiersIdentifier() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.CertifiersIdentifier
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSPRole governs the organization of the Principal
|
||||||
|
// field of an MSPPrincipal when it aims to define one of the
|
||||||
|
// two dedicated roles within an MSP: Admin and Members.
|
||||||
|
type MSPRole struct {
|
||||||
|
// MSPIdentifier represents the identifier of the MSP this principal
|
||||||
|
// refers to
|
||||||
|
MspIdentifier string `protobuf:"bytes,1,opt,name=msp_identifier,json=mspIdentifier,proto3" json:"msp_identifier,omitempty"`
|
||||||
|
// MSPRoleType defines which of the available, pre-defined MSP-roles
|
||||||
|
// an identiy should posess inside the MSP with identifier MSPidentifier
|
||||||
|
Role MSPRole_MSPRoleType `protobuf:"varint,2,opt,name=role,proto3,enum=common.MSPRole_MSPRoleType" json:"role,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPRole) Reset() { *m = MSPRole{} }
|
||||||
|
func (m *MSPRole) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*MSPRole) ProtoMessage() {}
|
||||||
|
func (*MSPRole) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{2}
|
||||||
|
}
|
||||||
|
func (m *MSPRole) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_MSPRole.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *MSPRole) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_MSPRole.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *MSPRole) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_MSPRole.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *MSPRole) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_MSPRole.Size(m)
|
||||||
|
}
|
||||||
|
func (m *MSPRole) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_MSPRole.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_MSPRole proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *MSPRole) GetMspIdentifier() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.MspIdentifier
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPRole) GetRole() MSPRole_MSPRoleType {
|
||||||
|
if m != nil {
|
||||||
|
return m.Role
|
||||||
|
}
|
||||||
|
return MSPRole_MEMBER
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSPIdentityAnonymity can be used to enforce an identity to be anonymous or nominal.
|
||||||
|
type MSPIdentityAnonymity struct {
|
||||||
|
AnonymityType MSPIdentityAnonymity_MSPIdentityAnonymityType `protobuf:"varint,1,opt,name=anonymity_type,json=anonymityType,proto3,enum=common.MSPIdentityAnonymity_MSPIdentityAnonymityType" json:"anonymity_type,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MSPIdentityAnonymity) Reset() { *m = MSPIdentityAnonymity{} }
|
||||||
|
func (m *MSPIdentityAnonymity) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*MSPIdentityAnonymity) ProtoMessage() {}
|
||||||
|
func (*MSPIdentityAnonymity) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{3}
|
||||||
|
}
|
||||||
|
func (m *MSPIdentityAnonymity) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_MSPIdentityAnonymity.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *MSPIdentityAnonymity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_MSPIdentityAnonymity.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *MSPIdentityAnonymity) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_MSPIdentityAnonymity.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *MSPIdentityAnonymity) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_MSPIdentityAnonymity.Size(m)
|
||||||
|
}
|
||||||
|
func (m *MSPIdentityAnonymity) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_MSPIdentityAnonymity.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_MSPIdentityAnonymity proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *MSPIdentityAnonymity) GetAnonymityType() MSPIdentityAnonymity_MSPIdentityAnonymityType {
|
||||||
|
if m != nil {
|
||||||
|
return m.AnonymityType
|
||||||
|
}
|
||||||
|
return MSPIdentityAnonymity_NOMINAL
|
||||||
|
}
|
||||||
|
|
||||||
|
// CombinedPrincipal governs the organization of the Principal
|
||||||
|
// field of a policy principal when principal_classification has
|
||||||
|
// indicated that a combined form of principals is required
|
||||||
|
type CombinedPrincipal struct {
|
||||||
|
// Principals refer to combined principals
|
||||||
|
Principals []*MSPPrincipal `protobuf:"bytes,1,rep,name=principals,proto3" json:"principals,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *CombinedPrincipal) Reset() { *m = CombinedPrincipal{} }
|
||||||
|
func (m *CombinedPrincipal) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*CombinedPrincipal) ProtoMessage() {}
|
||||||
|
func (*CombinedPrincipal) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_msp_principal_9016cf1a8a7156cd, []int{4}
|
||||||
|
}
|
||||||
|
func (m *CombinedPrincipal) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_CombinedPrincipal.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *CombinedPrincipal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_CombinedPrincipal.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (dst *CombinedPrincipal) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_CombinedPrincipal.Merge(dst, src)
|
||||||
|
}
|
||||||
|
func (m *CombinedPrincipal) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_CombinedPrincipal.Size(m)
|
||||||
|
}
|
||||||
|
func (m *CombinedPrincipal) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_CombinedPrincipal.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_CombinedPrincipal proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *CombinedPrincipal) GetPrincipals() []*MSPPrincipal {
|
||||||
|
if m != nil {
|
||||||
|
return m.Principals
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*MSPPrincipal)(nil), "common.MSPPrincipal")
|
||||||
|
proto.RegisterType((*OrganizationUnit)(nil), "common.OrganizationUnit")
|
||||||
|
proto.RegisterType((*MSPRole)(nil), "common.MSPRole")
|
||||||
|
proto.RegisterType((*MSPIdentityAnonymity)(nil), "common.MSPIdentityAnonymity")
|
||||||
|
proto.RegisterType((*CombinedPrincipal)(nil), "common.CombinedPrincipal")
|
||||||
|
proto.RegisterEnum("common.MSPPrincipal_Classification", MSPPrincipal_Classification_name, MSPPrincipal_Classification_value)
|
||||||
|
proto.RegisterEnum("common.MSPRole_MSPRoleType", MSPRole_MSPRoleType_name, MSPRole_MSPRoleType_value)
|
||||||
|
proto.RegisterEnum("common.MSPIdentityAnonymity_MSPIdentityAnonymityType", MSPIdentityAnonymity_MSPIdentityAnonymityType_name, MSPIdentityAnonymity_MSPIdentityAnonymityType_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterFile("msp/msp_principal.proto", fileDescriptor_msp_principal_9016cf1a8a7156cd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileDescriptor_msp_principal_9016cf1a8a7156cd = []byte{
|
||||||
|
// 519 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xdf, 0x6a, 0xdb, 0x30,
|
||||||
|
0x14, 0xc6, 0xeb, 0xa4, 0x6b, 0x9b, 0x93, 0x3f, 0xa8, 0x22, 0xa5, 0x81, 0x95, 0x11, 0xbc, 0x0d,
|
||||||
|
0x72, 0xe5, 0x40, 0xba, 0xed, 0x62, 0x77, 0x4e, 0x62, 0x86, 0x20, 0x96, 0x8d, 0xe3, 0x5c, 0xb4,
|
||||||
|
0x94, 0x05, 0xc7, 0x51, 0x52, 0x81, 0x6d, 0x19, 0xdb, 0xbd, 0xf0, 0xde, 0x65, 0x6f, 0xb0, 0xcb,
|
||||||
|
0x3d, 0xd5, 0x9e, 0x62, 0xd8, 0x6e, 0x12, 0x65, 0xeb, 0x60, 0x57, 0xf6, 0x39, 0xe7, 0xf7, 0x1d,
|
||||||
|
0x1d, 0x49, 0x9f, 0xe0, 0x3a, 0x4c, 0xe3, 0x61, 0x98, 0xc6, 0xcb, 0x38, 0xe1, 0x91, 0xcf, 0x63,
|
||||||
|
0x2f, 0xd0, 0xe2, 0x44, 0x64, 0x02, 0x9f, 0xf9, 0x22, 0x0c, 0x45, 0xa4, 0xfe, 0x52, 0xa0, 0x65,
|
||||||
|
0xce, 0x6d, 0x7b, 0x57, 0xc6, 0x5f, 0xa1, 0xb7, 0x67, 0x97, 0x7e, 0xe0, 0xa5, 0x29, 0xdf, 0x70,
|
||||||
|
0xdf, 0xcb, 0xb8, 0x88, 0x7a, 0x4a, 0x5f, 0x19, 0x74, 0x46, 0x6f, 0xb5, 0x4a, 0xab, 0xc9, 0x3a,
|
||||||
|
0x6d, 0x72, 0x84, 0x3a, 0xd7, 0xfb, 0x26, 0xc7, 0x05, 0x7c, 0x03, 0x8d, 0x7d, 0xa9, 0x57, 0xeb,
|
||||||
|
0x2b, 0x83, 0x96, 0x73, 0x48, 0xa8, 0x0f, 0xd0, 0xf9, 0x83, 0xbf, 0x80, 0x53, 0xc7, 0x9a, 0x19,
|
||||||
|
0xe8, 0x04, 0x5f, 0xc1, 0xa5, 0xe5, 0x7c, 0xd1, 0x29, 0xb9, 0xd7, 0x5d, 0x62, 0xd1, 0xe5, 0x82,
|
||||||
|
0x12, 0x17, 0x29, 0xb8, 0x05, 0x17, 0x64, 0x6a, 0x50, 0x97, 0xb8, 0x77, 0xa8, 0x86, 0xdb, 0xd0,
|
||||||
|
0xd0, 0xa9, 0x45, 0xef, 0xcc, 0x22, 0xac, 0x17, 0xc5, 0x89, 0x65, 0x8e, 0x09, 0x35, 0xa6, 0xe8,
|
||||||
|
0x54, 0xfd, 0xa9, 0x00, 0xb2, 0x92, 0xad, 0x17, 0xf1, 0x6f, 0x65, 0xf3, 0x45, 0xc4, 0x33, 0xfc,
|
||||||
|
0x1e, 0x3a, 0xc5, 0x01, 0xf1, 0x35, 0x8b, 0x32, 0xbe, 0xe1, 0x2c, 0x29, 0xb7, 0xd9, 0x70, 0xda,
|
||||||
|
0x61, 0x1a, 0x93, 0x7d, 0x12, 0x4f, 0xe1, 0x8d, 0x90, 0xa4, 0x5e, 0xb0, 0x7c, 0x8a, 0x78, 0x26,
|
||||||
|
0xcb, 0x6a, 0xa5, 0xec, 0xe6, 0x98, 0x2a, 0x96, 0x90, 0xba, 0xdc, 0xc2, 0x95, 0xcf, 0x92, 0x2a,
|
||||||
|
0x48, 0x65, 0x71, 0xbd, 0x3c, 0x89, 0xee, 0xa1, 0x78, 0x10, 0xa9, 0xdf, 0x15, 0x38, 0x37, 0xe7,
|
||||||
|
0xb6, 0x23, 0x02, 0xf6, 0xbf, 0xd3, 0x0e, 0xe1, 0x34, 0x11, 0x01, 0x2b, 0x67, 0xea, 0x8c, 0x5e,
|
||||||
|
0x4b, 0x37, 0x56, 0x74, 0xd9, 0x7d, 0xdd, 0x3c, 0x66, 0x4e, 0x09, 0xaa, 0x9f, 0xa1, 0x29, 0x25,
|
||||||
|
0x31, 0xc0, 0x99, 0x69, 0x98, 0x63, 0xc3, 0x41, 0x27, 0xb8, 0x01, 0xaf, 0xf4, 0xa9, 0x49, 0x28,
|
||||||
|
0x52, 0x8a, 0xf4, 0x64, 0x46, 0x0c, 0xea, 0xa2, 0x5a, 0x71, 0x31, 0xb6, 0x61, 0x38, 0xa8, 0xae,
|
||||||
|
0xfe, 0x50, 0xa0, 0x6b, 0xce, 0xed, 0x6a, 0xf9, 0x2c, 0xd7, 0x23, 0x11, 0xe5, 0x21, 0xcf, 0x72,
|
||||||
|
0xfc, 0x00, 0x1d, 0x6f, 0x17, 0x2c, 0xb3, 0x3c, 0x66, 0xcf, 0x0e, 0xfa, 0x28, 0xcd, 0xf3, 0x97,
|
||||||
|
0xea, 0xc5, 0x64, 0x39, 0x69, 0xdb, 0x93, 0x43, 0xf5, 0x13, 0xf4, 0xfe, 0x85, 0xe2, 0x26, 0x9c,
|
||||||
|
0x53, 0xcb, 0x24, 0x54, 0x9f, 0xa1, 0x93, 0x83, 0x27, 0xac, 0xc5, 0x1c, 0x29, 0x2a, 0x81, 0xcb,
|
||||||
|
0x89, 0x08, 0x57, 0x3c, 0x62, 0xeb, 0x83, 0xed, 0x3f, 0x00, 0xec, 0x5d, 0x98, 0xf6, 0x94, 0x7e,
|
||||||
|
0x7d, 0xd0, 0x1c, 0x75, 0x5f, 0x32, 0xba, 0x23, 0x71, 0x63, 0x1b, 0xde, 0x89, 0x64, 0xab, 0x3d,
|
||||||
|
0xe6, 0x31, 0x4b, 0x02, 0xb6, 0xde, 0xb2, 0x44, 0xdb, 0x78, 0xab, 0x84, 0xfb, 0xd5, 0x2b, 0x4b,
|
||||||
|
0x9f, 0x1b, 0xdc, 0x0f, 0xb6, 0x3c, 0x7b, 0x7c, 0x5a, 0x15, 0xe1, 0x50, 0x82, 0x87, 0x15, 0x3c,
|
||||||
|
0xac, 0xe0, 0xe2, 0x9d, 0xae, 0xce, 0xca, 0xff, 0xdb, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40,
|
||||||
|
0x36, 0xd2, 0xf9, 0xb9, 0x03, 0x00, 0x00,
|
||||||
|
}
|
||||||
153
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_principal.proto
generated
vendored
Normal file
153
chaincode/abac/go/vendor/github.com/hyperledger/fabric/protos/msp/msp_principal.proto
generated
vendored
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
/*
|
||||||
|
Copyright IBM Corp. 2016 All Rights Reserved.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option go_package = "github.com/hyperledger/fabric/protos/msp";
|
||||||
|
option java_package = "org.hyperledger.fabric.protos.common";
|
||||||
|
|
||||||
|
package common;
|
||||||
|
|
||||||
|
|
||||||
|
// msp_principal.proto contains proto messages defining the generalized
|
||||||
|
// MSP notion of identity called an MSPPrincipal. It is used as part of
|
||||||
|
// the chain configuration, in particular as the identity parameters to
|
||||||
|
// the configuration.proto file. This does not represent the MSP
|
||||||
|
// configuration for a chain, but is understood by MSPs
|
||||||
|
|
||||||
|
// MSPPrincipal aims to represent an MSP-centric set of identities.
|
||||||
|
// In particular, this structure allows for definition of
|
||||||
|
// - a group of identities that are member of the same MSP
|
||||||
|
// - a group of identities that are member of the same organization unit
|
||||||
|
// in the same MSP
|
||||||
|
// - a group of identities that are administering a specific MSP
|
||||||
|
// - a specific identity
|
||||||
|
// Expressing these groups is done given two fields of the fields below
|
||||||
|
// - Classification, that defines the type of classification of identities
|
||||||
|
// in an MSP this principal would be defined on; Classification can take
|
||||||
|
// three values:
|
||||||
|
// (i) ByMSPRole: that represents a classification of identities within
|
||||||
|
// MSP based on one of the two pre-defined MSP rules, "member" and "admin"
|
||||||
|
// (ii) ByOrganizationUnit: that represents a classification of identities
|
||||||
|
// within MSP based on the organization unit an identity belongs to
|
||||||
|
// (iii)ByIdentity that denotes that MSPPrincipal is mapped to a single
|
||||||
|
// identity/certificate; this would mean that the Principal bytes
|
||||||
|
// message
|
||||||
|
message MSPPrincipal {
|
||||||
|
|
||||||
|
enum Classification {
|
||||||
|
ROLE = 0; // Represents the one of the dedicated MSP roles, the
|
||||||
|
// one of a member of MSP network, and the one of an
|
||||||
|
// administrator of an MSP network
|
||||||
|
ORGANIZATION_UNIT = 1; // Denotes a finer grained (affiliation-based)
|
||||||
|
// groupping of entities, per MSP affiliation
|
||||||
|
// E.g., this can well be represented by an MSP's
|
||||||
|
// Organization unit
|
||||||
|
IDENTITY = 2; // Denotes a principal that consists of a single
|
||||||
|
// identity
|
||||||
|
ANONYMITY = 3; // Denotes a principal that can be used to enforce
|
||||||
|
// an identity to be anonymous or nominal.
|
||||||
|
COMBINED = 4; // Denotes a combined principal
|
||||||
|
}
|
||||||
|
|
||||||
|
// Classification describes the way that one should process
|
||||||
|
// Principal. An Classification value of "ByOrganizationUnit" reflects
|
||||||
|
// that "Principal" contains the name of an organization this MSP
|
||||||
|
// handles. A Classification value "ByIdentity" means that
|
||||||
|
// "Principal" contains a specific identity. Default value
|
||||||
|
// denotes that Principal contains one of the groups by
|
||||||
|
// default supported by all MSPs ("admin" or "member").
|
||||||
|
Classification principal_classification = 1;
|
||||||
|
|
||||||
|
// Principal completes the policy principal definition. For the default
|
||||||
|
// principal types, Principal can be either "Admin" or "Member".
|
||||||
|
// For the ByOrganizationUnit/ByIdentity values of Classification,
|
||||||
|
// PolicyPrincipal acquires its value from an organization unit or
|
||||||
|
// identity, respectively.
|
||||||
|
// For the Combined Classification type, the Principal is a marshalled
|
||||||
|
// CombinedPrincipal.
|
||||||
|
bytes principal = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// OrganizationUnit governs the organization of the Principal
|
||||||
|
// field of a policy principal when a specific organization unity members
|
||||||
|
// are to be defined within a policy principal.
|
||||||
|
message OrganizationUnit {
|
||||||
|
|
||||||
|
// MSPIdentifier represents the identifier of the MSP this organization unit
|
||||||
|
// refers to
|
||||||
|
string msp_identifier = 1;
|
||||||
|
|
||||||
|
// OrganizationUnitIdentifier defines the organizational unit under the
|
||||||
|
// MSP identified with MSPIdentifier
|
||||||
|
string organizational_unit_identifier = 2;
|
||||||
|
|
||||||
|
// CertifiersIdentifier is the hash of certificates chain of trust
|
||||||
|
// related to this organizational unit
|
||||||
|
bytes certifiers_identifier = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSPRole governs the organization of the Principal
|
||||||
|
// field of an MSPPrincipal when it aims to define one of the
|
||||||
|
// two dedicated roles within an MSP: Admin and Members.
|
||||||
|
message MSPRole {
|
||||||
|
|
||||||
|
// MSPIdentifier represents the identifier of the MSP this principal
|
||||||
|
// refers to
|
||||||
|
string msp_identifier = 1;
|
||||||
|
|
||||||
|
enum MSPRoleType {
|
||||||
|
MEMBER = 0; // Represents an MSP Member
|
||||||
|
ADMIN = 1; // Represents an MSP Admin
|
||||||
|
CLIENT = 2; // Represents an MSP Client
|
||||||
|
PEER = 3; // Represents an MSP Peer
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSPRoleType defines which of the available, pre-defined MSP-roles
|
||||||
|
// an identiy should posess inside the MSP with identifier MSPidentifier
|
||||||
|
MSPRoleType role = 2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSPIdentityAnonymity can be used to enforce an identity to be anonymous or nominal.
|
||||||
|
message MSPIdentityAnonymity {
|
||||||
|
|
||||||
|
enum MSPIdentityAnonymityType {
|
||||||
|
NOMINAL = 0; // Represents a nominal MSP Identity
|
||||||
|
ANONYMOUS = 1; // Represents an anonymous MSP Identity
|
||||||
|
}
|
||||||
|
|
||||||
|
MSPIdentityAnonymityType anonymity_type = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// CombinedPrincipal governs the organization of the Principal
|
||||||
|
// field of a policy principal when principal_classification has
|
||||||
|
// indicated that a combined form of principals is required
|
||||||
|
message CombinedPrincipal {
|
||||||
|
|
||||||
|
// Principals refer to combined principals
|
||||||
|
repeated MSPPrincipal principals = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Bring msp.SerializedIdentity from fabric/msp/identities.proto here. Reason below.
|
||||||
|
// SerializedIdentity represents an serialized version of an identity;
|
||||||
|
// this consists of an MSP-identifier this identity would correspond to
|
||||||
|
// and the bytes of the actual identity. A serialized form of
|
||||||
|
// SerializedIdentity would govern "Principal" field of a PolicyPrincipal
|
||||||
|
// of classification "ByIdentity".
|
||||||
43
chaincode/abac/go/vendor/github.com/pkg/errors/errors.go
generated
vendored
43
chaincode/abac/go/vendor/github.com/pkg/errors/errors.go
generated
vendored
|
|
@ -6,7 +6,7 @@
|
||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// which applied recursively up the call stack results in error reports
|
// which when applied recursively up the call stack results in error reports
|
||||||
// without context or debugging information. The errors package allows
|
// without context or debugging information. The errors package allows
|
||||||
// programmers to add context to the failure path in their code in a way
|
// programmers to add context to the failure path in their code in a way
|
||||||
// that does not destroy the original value of the error.
|
// that does not destroy the original value of the error.
|
||||||
|
|
@ -15,16 +15,17 @@
|
||||||
//
|
//
|
||||||
// The errors.Wrap function returns a new error that adds context to the
|
// The errors.Wrap function returns a new error that adds context to the
|
||||||
// original error by recording a stack trace at the point Wrap is called,
|
// original error by recording a stack trace at the point Wrap is called,
|
||||||
// and the supplied message. For example
|
// together with the supplied message. For example
|
||||||
//
|
//
|
||||||
// _, err := ioutil.ReadAll(r)
|
// _, err := ioutil.ReadAll(r)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return errors.Wrap(err, "read failed")
|
// return errors.Wrap(err, "read failed")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// If additional control is required the errors.WithStack and errors.WithMessage
|
// If additional control is required, the errors.WithStack and
|
||||||
// functions destructure errors.Wrap into its component operations of annotating
|
// errors.WithMessage functions destructure errors.Wrap into its component
|
||||||
// an error with a stack trace and an a message, respectively.
|
// operations: annotating an error with a stack trace and with a message,
|
||||||
|
// respectively.
|
||||||
//
|
//
|
||||||
// Retrieving the cause of an error
|
// Retrieving the cause of an error
|
||||||
//
|
//
|
||||||
|
|
@ -38,7 +39,7 @@
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// can be inspected by errors.Cause. errors.Cause will recursively retrieve
|
// can be inspected by errors.Cause. errors.Cause will recursively retrieve
|
||||||
// the topmost error which does not implement causer, which is assumed to be
|
// the topmost error that does not implement causer, which is assumed to be
|
||||||
// the original cause. For example:
|
// the original cause. For example:
|
||||||
//
|
//
|
||||||
// switch err := errors.Cause(err).(type) {
|
// switch err := errors.Cause(err).(type) {
|
||||||
|
|
@ -48,16 +49,16 @@
|
||||||
// // unknown error
|
// // unknown error
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// causer interface is not exported by this package, but is considered a part
|
// Although the causer interface is not exported by this package, it is
|
||||||
// of stable public API.
|
// considered a part of its stable public interface.
|
||||||
//
|
//
|
||||||
// Formatted printing of errors
|
// Formatted printing of errors
|
||||||
//
|
//
|
||||||
// All error values returned from this package implement fmt.Formatter and can
|
// All error values returned from this package implement fmt.Formatter and can
|
||||||
// be formatted by the fmt package. The following verbs are supported
|
// be formatted by the fmt package. The following verbs are supported:
|
||||||
//
|
//
|
||||||
// %s print the error. If the error has a Cause it will be
|
// %s print the error. If the error has a Cause it will be
|
||||||
// printed recursively
|
// printed recursively.
|
||||||
// %v see %s
|
// %v see %s
|
||||||
// %+v extended format. Each Frame of the error's StackTrace will
|
// %+v extended format. Each Frame of the error's StackTrace will
|
||||||
// be printed in detail.
|
// be printed in detail.
|
||||||
|
|
@ -65,13 +66,13 @@
|
||||||
// Retrieving the stack trace of an error or wrapper
|
// Retrieving the stack trace of an error or wrapper
|
||||||
//
|
//
|
||||||
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
|
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
|
||||||
// invoked. This information can be retrieved with the following interface.
|
// invoked. This information can be retrieved with the following interface:
|
||||||
//
|
//
|
||||||
// type stackTracer interface {
|
// type stackTracer interface {
|
||||||
// StackTrace() errors.StackTrace
|
// StackTrace() errors.StackTrace
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Where errors.StackTrace is defined as
|
// The returned errors.StackTrace type is defined as
|
||||||
//
|
//
|
||||||
// type StackTrace []Frame
|
// type StackTrace []Frame
|
||||||
//
|
//
|
||||||
|
|
@ -85,8 +86,8 @@
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// stackTracer interface is not exported by this package, but is considered a part
|
// Although the stackTracer interface is not exported by this package, it is
|
||||||
// of stable public API.
|
// considered a part of its stable public interface.
|
||||||
//
|
//
|
||||||
// See the documentation for Frame.Format for more details.
|
// See the documentation for Frame.Format for more details.
|
||||||
package errors
|
package errors
|
||||||
|
|
@ -192,7 +193,7 @@ func Wrap(err error, message string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapf returns an error annotating err with a stack trace
|
// Wrapf returns an error annotating err with a stack trace
|
||||||
// at the point Wrapf is call, and the format specifier.
|
// at the point Wrapf is called, and the format specifier.
|
||||||
// If err is nil, Wrapf returns nil.
|
// If err is nil, Wrapf returns nil.
|
||||||
func Wrapf(err error, format string, args ...interface{}) error {
|
func Wrapf(err error, format string, args ...interface{}) error {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -220,6 +221,18 @@ func WithMessage(err error, message string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithMessagef annotates err with the format specifier.
|
||||||
|
// If err is nil, WithMessagef returns nil.
|
||||||
|
func WithMessagef(err error, format string, args ...interface{}) error {
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &withMessage{
|
||||||
|
cause: err,
|
||||||
|
msg: fmt.Sprintf(format, args...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type withMessage struct {
|
type withMessage struct {
|
||||||
cause error
|
cause error
|
||||||
msg string
|
msg string
|
||||||
|
|
|
||||||
34
chaincode/abac/go/vendor/vendor.json
vendored
34
chaincode/abac/go/vendor/vendor.json
vendored
|
|
@ -3,28 +3,34 @@
|
||||||
"ignore": "test",
|
"ignore": "test",
|
||||||
"package": [
|
"package": [
|
||||||
{
|
{
|
||||||
"checksumSHA1": "WX1+2gktHcBmE9MGwFSGs7oqexU=",
|
"checksumSHA1": "GaJLoEuMGnP5ofXvuweAI4wx06U=",
|
||||||
"path": "github.com/golang/protobuf/proto",
|
"path": "github.com/golang/protobuf/proto",
|
||||||
"revision": "bbd03ef6da3a115852eaf24c8a1c46aeb39aa175",
|
"revision": "1918e1ff6ffd2be7bed0553df8650672c3bfe80d",
|
||||||
"revisionTime": "2018-02-02T18:43:18Z"
|
"revisionTime": "2018-10-30T15:47:21Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "n+ZKx3gMoBi4t0fN84vzz0r2uCM=",
|
"checksumSHA1": "XGpUl1X+7ly1ski4Pc+N9ozfVv8=",
|
||||||
"path": "github.com/hyperledger/fabric/common/attrmgr",
|
"path": "github.com/hyperledger/fabric/core/chaincode/shim/ext/attrmgr",
|
||||||
"revision": "37d68a18f6afa156c1145900feaa16d2f558cfe5",
|
"revision": "60f968db8e6e2ebcf439391610e22250993d0a85",
|
||||||
"revisionTime": "2018-02-26T20:04:44Z"
|
"revisionTime": "2018-09-12T02:19:31Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "y8UGqcO/ZWyUDSrSy/ANg64vOvs=",
|
"checksumSHA1": "vFuT7942CfsCcH9IG3zHmQ4d/oI=",
|
||||||
"path": "github.com/hyperledger/fabric/core/chaincode/lib/cid",
|
"path": "github.com/hyperledger/fabric/core/chaincode/shim/ext/cid",
|
||||||
"revision": "37d68a18f6afa156c1145900feaa16d2f558cfe5",
|
"revision": "60f968db8e6e2ebcf439391610e22250993d0a85",
|
||||||
"revisionTime": "2018-02-26T20:04:44Z"
|
"revisionTime": "2018-09-12T02:19:31Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "ljd3FhYRJ91cLZz3wsH9BQQ2JbA=",
|
"checksumSHA1": "ZzWCzHsWRI/LAxhZYUMqVcIAsZQ=",
|
||||||
|
"path": "github.com/hyperledger/fabric/protos/msp",
|
||||||
|
"revision": "60f968db8e6e2ebcf439391610e22250993d0a85",
|
||||||
|
"revisionTime": "2018-09-12T02:19:31Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "DTy0iJ2w5C+FDsN9EnzfhNmvS+o=",
|
||||||
"path": "github.com/pkg/errors",
|
"path": "github.com/pkg/errors",
|
||||||
"revision": "30136e27e2ac8d167177e8a583aa4c3fea5be833",
|
"revision": "059132a15dd08d6704c67711dae0cf35ab991756",
|
||||||
"revisionTime": "2018-01-27T01:58:12Z"
|
"revisionTime": "2018-10-23T23:59:46Z"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rootPath": "github.com/hyperledger/fabric-samples/chaincode/abac/go"
|
"rootPath": "github.com/hyperledger/fabric-samples/chaincode/abac/go"
|
||||||
|
|
|
||||||
34
chaincode/chaincode_example02/java/build.gradle
Normal file
34
chaincode/chaincode_example02/java/build.gradle
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright IBM Corp. 2018 All Rights Reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
plugins {
|
||||||
|
id 'com.github.johnrengelman.shadow' version '2.0.3'
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'org.hyperledger.fabric-chaincode-java'
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
baseName = 'chaincode'
|
||||||
|
version = null
|
||||||
|
classifier = null
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
|
||||||
|
}
|
||||||
|
}
|
||||||
7
chaincode/chaincode_example02/java/settings.gradle
Normal file
7
chaincode/chaincode_example02/java/settings.gradle
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
/*
|
||||||
|
* Copyright IBM Corp. 2017 All Rights Reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
rootProject.name = 'fabric-chaincode-example-gradle'
|
||||||
|
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
Copyright IBM Corp., DTCC All Rights Reserved.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
package org.hyperledger.fabric.example;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import io.netty.handler.ssl.OpenSsl;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.hyperledger.fabric.shim.ChaincodeBase;
|
||||||
|
import org.hyperledger.fabric.shim.ChaincodeStub;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
public class SimpleChaincode extends ChaincodeBase {
|
||||||
|
|
||||||
|
private static Log _logger = LogFactory.getLog(SimpleChaincode.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response init(ChaincodeStub stub) {
|
||||||
|
try {
|
||||||
|
_logger.info("Init java simple chaincode");
|
||||||
|
String func = stub.getFunction();
|
||||||
|
if (!func.equals("init")) {
|
||||||
|
return newErrorResponse("function other than init is not supported");
|
||||||
|
}
|
||||||
|
List<String> args = stub.getParameters();
|
||||||
|
if (args.size() != 4) {
|
||||||
|
newErrorResponse("Incorrect number of arguments. Expecting 4");
|
||||||
|
}
|
||||||
|
// Initialize the chaincode
|
||||||
|
String account1Key = args.get(0);
|
||||||
|
int account1Value = Integer.parseInt(args.get(1));
|
||||||
|
String account2Key = args.get(2);
|
||||||
|
int account2Value = Integer.parseInt(args.get(3));
|
||||||
|
|
||||||
|
_logger.info(String.format("account %s, value = %s; account %s, value %s", account1Key, account1Value, account2Key, account2Value));
|
||||||
|
stub.putStringState(account1Key, args.get(1));
|
||||||
|
stub.putStringState(account2Key, args.get(3));
|
||||||
|
|
||||||
|
return newSuccessResponse();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return newErrorResponse(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response invoke(ChaincodeStub stub) {
|
||||||
|
try {
|
||||||
|
_logger.info("Invoke java simple chaincode");
|
||||||
|
String func = stub.getFunction();
|
||||||
|
List<String> params = stub.getParameters();
|
||||||
|
if (func.equals("invoke")) {
|
||||||
|
return invoke(stub, params);
|
||||||
|
}
|
||||||
|
if (func.equals("delete")) {
|
||||||
|
return delete(stub, params);
|
||||||
|
}
|
||||||
|
if (func.equals("query")) {
|
||||||
|
return query(stub, params);
|
||||||
|
}
|
||||||
|
return newErrorResponse("Invalid invoke function name. Expecting one of: [\"invoke\", \"delete\", \"query\"]");
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return newErrorResponse(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response invoke(ChaincodeStub stub, List<String> args) {
|
||||||
|
if (args.size() != 3) {
|
||||||
|
return newErrorResponse("Incorrect number of arguments. Expecting 3");
|
||||||
|
}
|
||||||
|
String accountFromKey = args.get(0);
|
||||||
|
String accountToKey = args.get(1);
|
||||||
|
|
||||||
|
String accountFromValueStr = stub.getStringState(accountFromKey);
|
||||||
|
if (accountFromValueStr == null) {
|
||||||
|
return newErrorResponse(String.format("Entity %s not found", accountFromKey));
|
||||||
|
}
|
||||||
|
int accountFromValue = Integer.parseInt(accountFromValueStr);
|
||||||
|
|
||||||
|
String accountToValueStr = stub.getStringState(accountToKey);
|
||||||
|
if (accountToValueStr == null) {
|
||||||
|
return newErrorResponse(String.format("Entity %s not found", accountToKey));
|
||||||
|
}
|
||||||
|
int accountToValue = Integer.parseInt(accountToValueStr);
|
||||||
|
|
||||||
|
int amount = Integer.parseInt(args.get(2));
|
||||||
|
|
||||||
|
if (amount > accountFromValue) {
|
||||||
|
return newErrorResponse(String.format("not enough money in account %s", accountFromKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
accountFromValue -= amount;
|
||||||
|
accountToValue += amount;
|
||||||
|
|
||||||
|
_logger.info(String.format("new value of A: %s", accountFromValue));
|
||||||
|
_logger.info(String.format("new value of B: %s", accountToValue));
|
||||||
|
|
||||||
|
stub.putStringState(accountFromKey, Integer.toString(accountFromValue));
|
||||||
|
stub.putStringState(accountToKey, Integer.toString(accountToValue));
|
||||||
|
|
||||||
|
_logger.info("Transfer complete");
|
||||||
|
|
||||||
|
return newSuccessResponse("invoke finished successfully", ByteString.copyFrom(accountFromKey + ": " + accountFromValue + " " + accountToKey + ": " + accountToValue, UTF_8).toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deletes an entity from state
|
||||||
|
private Response delete(ChaincodeStub stub, List<String> args) {
|
||||||
|
if (args.size() != 1) {
|
||||||
|
return newErrorResponse("Incorrect number of arguments. Expecting 1");
|
||||||
|
}
|
||||||
|
String key = args.get(0);
|
||||||
|
// Delete the key from the state in ledger
|
||||||
|
stub.delState(key);
|
||||||
|
return newSuccessResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// query callback representing the query of a chaincode
|
||||||
|
private Response query(ChaincodeStub stub, List<String> args) {
|
||||||
|
if (args.size() != 1) {
|
||||||
|
return newErrorResponse("Incorrect number of arguments. Expecting name of the person to query");
|
||||||
|
}
|
||||||
|
String key = args.get(0);
|
||||||
|
//byte[] stateBytes
|
||||||
|
String val = stub.getStringState(key);
|
||||||
|
if (val == null) {
|
||||||
|
return newErrorResponse(String.format("Error: state for %s is null", key));
|
||||||
|
}
|
||||||
|
_logger.info(String.format("Query Response:\nName: %s, Amount: %s\n", key, val));
|
||||||
|
return newSuccessResponse(val, ByteString.copyFrom(val, UTF_8).toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("OpenSSL avaliable: " + OpenSsl.isAvailable());
|
||||||
|
new SimpleChaincode().start(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
chaincode/fabcar/javascript/.editorconfig
Executable file
16
chaincode/fabcar/javascript/.editorconfig
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
5
chaincode/fabcar/javascript/.eslintignore
Normal file
5
chaincode/fabcar/javascript/.eslintignore
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
coverage
|
||||||
38
chaincode/fabcar/javascript/.eslintrc.js
Normal file
38
chaincode/fabcar/javascript/.eslintrc.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
mocha: true
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 8,
|
||||||
|
sourceType: 'script'
|
||||||
|
},
|
||||||
|
extends: "eslint:recommended",
|
||||||
|
rules: {
|
||||||
|
indent: ['error', 4],
|
||||||
|
'linebreak-style': ['error', 'unix'],
|
||||||
|
quotes: ['error', 'single'],
|
||||||
|
semi: ['error', 'always'],
|
||||||
|
'no-unused-vars': ['error', { args: 'none' }],
|
||||||
|
'no-console': 'off',
|
||||||
|
curly: 'error',
|
||||||
|
eqeqeq: 'error',
|
||||||
|
'no-throw-literal': 'error',
|
||||||
|
strict: 'error',
|
||||||
|
'no-var': 'error',
|
||||||
|
'dot-notation': 'error',
|
||||||
|
'no-tabs': 'error',
|
||||||
|
'no-trailing-spaces': 'error',
|
||||||
|
'no-use-before-define': 'error',
|
||||||
|
'no-useless-call': 'error',
|
||||||
|
'no-with': 'error',
|
||||||
|
'operator-linebreak': 'error',
|
||||||
|
yoda: 'error',
|
||||||
|
'quote-props': ['error', 'as-needed'],
|
||||||
|
'no-constant-condition': ["error", { "checkLoops": false }]
|
||||||
|
}
|
||||||
|
};
|
||||||
77
chaincode/fabcar/javascript/.gitignore
vendored
Normal file
77
chaincode/fabcar/javascript/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# nuxt.js build output
|
||||||
|
.nuxt
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless
|
||||||
10
chaincode/fabcar/javascript/index.js
Normal file
10
chaincode/fabcar/javascript/index.js
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const FabCar = require('./lib/fabcar');
|
||||||
|
|
||||||
|
module.exports.FabCar = FabCar;
|
||||||
|
module.exports.contracts = [ FabCar ];
|
||||||
156
chaincode/fabcar/javascript/lib/fabcar.js
Normal file
156
chaincode/fabcar/javascript/lib/fabcar.js
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { Contract } = require('fabric-contract-api');
|
||||||
|
|
||||||
|
class FabCar extends Contract {
|
||||||
|
|
||||||
|
async initLedger(ctx) {
|
||||||
|
console.info('============= START : Initialize Ledger ===========');
|
||||||
|
const cars = [
|
||||||
|
{
|
||||||
|
color: 'blue',
|
||||||
|
make: 'Toyota',
|
||||||
|
model: 'Prius',
|
||||||
|
owner: 'Tomoko',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'red',
|
||||||
|
make: 'Ford',
|
||||||
|
model: 'Mustang',
|
||||||
|
owner: 'Brad',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'green',
|
||||||
|
make: 'Hyundai',
|
||||||
|
model: 'Tucson',
|
||||||
|
owner: 'Jin Soo',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'yellow',
|
||||||
|
make: 'Volkswagen',
|
||||||
|
model: 'Passat',
|
||||||
|
owner: 'Max',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'black',
|
||||||
|
make: 'Tesla',
|
||||||
|
model: 'S',
|
||||||
|
owner: 'Adriana',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'purple',
|
||||||
|
make: 'Peugeot',
|
||||||
|
model: '205',
|
||||||
|
owner: 'Michel',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'white',
|
||||||
|
make: 'Chery',
|
||||||
|
model: 'S22L',
|
||||||
|
owner: 'Aarav',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'violet',
|
||||||
|
make: 'Fiat',
|
||||||
|
model: 'Punto',
|
||||||
|
owner: 'Pari',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'indigo',
|
||||||
|
make: 'Tata',
|
||||||
|
model: 'Nano',
|
||||||
|
owner: 'Valeria',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'brown',
|
||||||
|
make: 'Holden',
|
||||||
|
model: 'Barina',
|
||||||
|
owner: 'Shotaro',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 0; i < cars.length; i++) {
|
||||||
|
cars[i].docType = 'car';
|
||||||
|
await ctx.stub.putState('CAR' + i, Buffer.from(JSON.stringify(cars[i])));
|
||||||
|
console.info('Added <--> ', cars[i]);
|
||||||
|
}
|
||||||
|
console.info('============= END : Initialize Ledger ===========');
|
||||||
|
}
|
||||||
|
|
||||||
|
async queryCar(ctx, carNumber) {
|
||||||
|
const carAsBytes = await ctx.stub.getState(carNumber); // get the car from chaincode state
|
||||||
|
if (!carAsBytes || carAsBytes.length === 0) {
|
||||||
|
throw new Error(`${carNumber} does not exist`);
|
||||||
|
}
|
||||||
|
console.log(carAsBytes.toString());
|
||||||
|
return carAsBytes.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
async createCar(ctx, carNumber, make, model, color, owner) {
|
||||||
|
console.info('============= START : Create Car ===========');
|
||||||
|
|
||||||
|
const car = {
|
||||||
|
color,
|
||||||
|
docType: 'car',
|
||||||
|
make,
|
||||||
|
model,
|
||||||
|
owner,
|
||||||
|
};
|
||||||
|
|
||||||
|
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car)));
|
||||||
|
console.info('============= END : Create Car ===========');
|
||||||
|
}
|
||||||
|
|
||||||
|
async queryAllCars(ctx) {
|
||||||
|
const startKey = 'CAR0';
|
||||||
|
const endKey = 'CAR999';
|
||||||
|
|
||||||
|
const iterator = await ctx.stub.getStateByRange(startKey, endKey);
|
||||||
|
|
||||||
|
const allResults = [];
|
||||||
|
while (true) {
|
||||||
|
const res = await iterator.next();
|
||||||
|
|
||||||
|
if (res.value && res.value.value.toString()) {
|
||||||
|
console.log(res.value.value.toString('utf8'));
|
||||||
|
|
||||||
|
const Key = res.value.key;
|
||||||
|
let Record;
|
||||||
|
try {
|
||||||
|
Record = JSON.parse(res.value.value.toString('utf8'));
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
Record = res.value.value.toString('utf8');
|
||||||
|
}
|
||||||
|
allResults.push({ Key, Record });
|
||||||
|
}
|
||||||
|
if (res.done) {
|
||||||
|
console.log('end of data');
|
||||||
|
await iterator.close();
|
||||||
|
console.info(allResults);
|
||||||
|
return JSON.stringify(allResults);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeCarOwner(ctx, carNumber, newOwner) {
|
||||||
|
console.info('============= START : changeCarOwner ===========');
|
||||||
|
|
||||||
|
const carAsBytes = await ctx.stub.getState(carNumber); // get the car from chaincode state
|
||||||
|
if (!carAsBytes || carAsBytes.length === 0) {
|
||||||
|
throw new Error(`${carNumber} does not exist`);
|
||||||
|
}
|
||||||
|
const car = JSON.parse(carAsBytes.toString());
|
||||||
|
car.owner = newOwner;
|
||||||
|
|
||||||
|
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car)));
|
||||||
|
console.info('============= END : changeCarOwner ===========');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = FabCar;
|
||||||
47
chaincode/fabcar/javascript/package.json
Normal file
47
chaincode/fabcar/javascript/package.json
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
{
|
||||||
|
"name": "fabcar",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "FabCar contract implemented in JavaScript",
|
||||||
|
"main": "index.js",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8",
|
||||||
|
"npm": ">=5"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint .",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"test": "nyc mocha --recursive",
|
||||||
|
"start": "fabric-chaincode-node start"
|
||||||
|
},
|
||||||
|
"engineStrict": true,
|
||||||
|
"author": "Hyperledger",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"fabric-contract-api": "1.4.0-beta",
|
||||||
|
"fabric-shim": "1.4.0-beta"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^4.1.2",
|
||||||
|
"eslint": "^4.19.1",
|
||||||
|
"mocha": "^5.2.0",
|
||||||
|
"nyc": "^12.0.2",
|
||||||
|
"sinon": "^6.0.0",
|
||||||
|
"sinon-chai": "^3.2.0"
|
||||||
|
},
|
||||||
|
"nyc": {
|
||||||
|
"exclude": [
|
||||||
|
"coverage/**",
|
||||||
|
"test/**"
|
||||||
|
],
|
||||||
|
"reporter": [
|
||||||
|
"text-summary",
|
||||||
|
"html"
|
||||||
|
],
|
||||||
|
"all": true,
|
||||||
|
"check-coverage": true,
|
||||||
|
"statements": 100,
|
||||||
|
"branches": 100,
|
||||||
|
"functions": 100,
|
||||||
|
"lines": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
16
chaincode/fabcar/typescript/.editorconfig
Executable file
16
chaincode/fabcar/typescript/.editorconfig
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
81
chaincode/fabcar/typescript/.gitignore
vendored
Normal file
81
chaincode/fabcar/typescript/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# nuxt.js build output
|
||||||
|
.nuxt
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless
|
||||||
|
|
||||||
|
# Compiled TypeScript files
|
||||||
|
dist
|
||||||
|
|
||||||
62
chaincode/fabcar/typescript/package.json
Normal file
62
chaincode/fabcar/typescript/package.json
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
"name": "fabcar",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "FabCar contract implemented in TypeScript",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"typings": "dist/index.d.ts",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8",
|
||||||
|
"npm": ">=5"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"lint": "tslint -c tslint.json 'src/**/*.ts'",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"test": "nyc mocha -r ts-node/register src/**/*.spec.ts",
|
||||||
|
"start": "fabric-chaincode-node start",
|
||||||
|
"build": "tsc",
|
||||||
|
"build:watch": "tsc -w",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
|
},
|
||||||
|
"engineStrict": true,
|
||||||
|
"author": "Hyperledger",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"fabric-contract-api": "1.4.0-beta",
|
||||||
|
"fabric-shim": "1.4.0-beta"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/chai": "^4.1.4",
|
||||||
|
"@types/mocha": "^5.2.3",
|
||||||
|
"@types/node": "^10.3.6",
|
||||||
|
"@types/sinon": "^5.0.1",
|
||||||
|
"@types/sinon-chai": "^3.2.0",
|
||||||
|
"chai": "^4.1.2",
|
||||||
|
"mocha": "^5.2.0",
|
||||||
|
"nyc": "^12.0.2",
|
||||||
|
"sinon": "^6.0.0",
|
||||||
|
"sinon-chai": "^3.2.0",
|
||||||
|
"ts-node": "^7.0.0",
|
||||||
|
"tslint": "^5.10.0",
|
||||||
|
"typescript": "^2.9.2"
|
||||||
|
},
|
||||||
|
"nyc": {
|
||||||
|
"extension": [
|
||||||
|
".ts",
|
||||||
|
".tsx"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"coverage/**",
|
||||||
|
"dist/**"
|
||||||
|
],
|
||||||
|
"reporter": [
|
||||||
|
"text-summary",
|
||||||
|
"html"
|
||||||
|
],
|
||||||
|
"all": true,
|
||||||
|
"check-coverage": true,
|
||||||
|
"statements": 100,
|
||||||
|
"branches": 100,
|
||||||
|
"functions": 100,
|
||||||
|
"lines": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
11
chaincode/fabcar/typescript/src/car.ts
Normal file
11
chaincode/fabcar/typescript/src/car.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class Car {
|
||||||
|
public docType?: string;
|
||||||
|
public color: string;
|
||||||
|
public make: string;
|
||||||
|
public model: string;
|
||||||
|
public owner: string;
|
||||||
|
}
|
||||||
153
chaincode/fabcar/typescript/src/fabcar.ts
Normal file
153
chaincode/fabcar/typescript/src/fabcar.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Context, Contract } from 'fabric-contract-api';
|
||||||
|
import { Car } from './car';
|
||||||
|
|
||||||
|
export class FabCar extends Contract {
|
||||||
|
|
||||||
|
public async initLedger(ctx: Context) {
|
||||||
|
console.info('============= START : Initialize Ledger ===========');
|
||||||
|
const cars: Car[] = [
|
||||||
|
{
|
||||||
|
color: 'blue',
|
||||||
|
make: 'Toyota',
|
||||||
|
model: 'Prius',
|
||||||
|
owner: 'Tomoko',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'red',
|
||||||
|
make: 'Ford',
|
||||||
|
model: 'Mustang',
|
||||||
|
owner: 'Brad',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'green',
|
||||||
|
make: 'Hyundai',
|
||||||
|
model: 'Tucson',
|
||||||
|
owner: 'Jin Soo',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'yellow',
|
||||||
|
make: 'Volkswagen',
|
||||||
|
model: 'Passat',
|
||||||
|
owner: 'Max',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'black',
|
||||||
|
make: 'Tesla',
|
||||||
|
model: 'S',
|
||||||
|
owner: 'Adriana',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'purple',
|
||||||
|
make: 'Peugeot',
|
||||||
|
model: '205',
|
||||||
|
owner: 'Michel',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'white',
|
||||||
|
make: 'Chery',
|
||||||
|
model: 'S22L',
|
||||||
|
owner: 'Aarav',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'violet',
|
||||||
|
make: 'Fiat',
|
||||||
|
model: 'Punto',
|
||||||
|
owner: 'Pari',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'indigo',
|
||||||
|
make: 'Tata',
|
||||||
|
model: 'Nano',
|
||||||
|
owner: 'Valeria',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'brown',
|
||||||
|
make: 'Holden',
|
||||||
|
model: 'Barina',
|
||||||
|
owner: 'Shotaro',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 0; i < cars.length; i++) {
|
||||||
|
cars[i].docType = 'car';
|
||||||
|
await ctx.stub.putState('CAR' + i, Buffer.from(JSON.stringify(cars[i])));
|
||||||
|
console.info('Added <--> ', cars[i]);
|
||||||
|
}
|
||||||
|
console.info('============= END : Initialize Ledger ===========');
|
||||||
|
}
|
||||||
|
|
||||||
|
public async queryCar(ctx: Context, carNumber: string): Promise<string> {
|
||||||
|
const carAsBytes = await ctx.stub.getState(carNumber); // get the car from chaincode state
|
||||||
|
if (!carAsBytes || carAsBytes.length === 0) {
|
||||||
|
throw new Error(`${carNumber} does not exist`);
|
||||||
|
}
|
||||||
|
console.log(carAsBytes.toString());
|
||||||
|
return carAsBytes.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createCar(ctx: Context, carNumber: string, make: string, model: string, color: string, owner: string) {
|
||||||
|
console.info('============= START : Create Car ===========');
|
||||||
|
|
||||||
|
const car: Car = {
|
||||||
|
color,
|
||||||
|
docType: 'car',
|
||||||
|
make,
|
||||||
|
model,
|
||||||
|
owner,
|
||||||
|
};
|
||||||
|
|
||||||
|
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car)));
|
||||||
|
console.info('============= END : Create Car ===========');
|
||||||
|
}
|
||||||
|
|
||||||
|
public async queryAllCars(ctx: Context): Promise<string> {
|
||||||
|
const startKey = 'CAR0';
|
||||||
|
const endKey = 'CAR999';
|
||||||
|
|
||||||
|
const iterator = await ctx.stub.getStateByRange(startKey, endKey);
|
||||||
|
|
||||||
|
const allResults = [];
|
||||||
|
while (true) {
|
||||||
|
const res = await iterator.next();
|
||||||
|
|
||||||
|
if (res.value && res.value.value.toString()) {
|
||||||
|
console.log(res.value.value.toString('utf8'));
|
||||||
|
|
||||||
|
const Key = res.value.key;
|
||||||
|
let Record;
|
||||||
|
try {
|
||||||
|
Record = JSON.parse(res.value.value.toString('utf8'));
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
Record = res.value.value.toString('utf8');
|
||||||
|
}
|
||||||
|
allResults.push({ Key, Record });
|
||||||
|
}
|
||||||
|
if (res.done) {
|
||||||
|
console.log('end of data');
|
||||||
|
await iterator.close();
|
||||||
|
console.info(allResults);
|
||||||
|
return JSON.stringify(allResults);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async changeCarOwner(ctx: Context, carNumber: string, newOwner: string) {
|
||||||
|
console.info('============= START : changeCarOwner ===========');
|
||||||
|
|
||||||
|
const carAsBytes = await ctx.stub.getState(carNumber); // get the car from chaincode state
|
||||||
|
if (!carAsBytes || carAsBytes.length === 0) {
|
||||||
|
throw new Error(`${carNumber} does not exist`);
|
||||||
|
}
|
||||||
|
const car: Car = JSON.parse(carAsBytes.toString());
|
||||||
|
car.owner = newOwner;
|
||||||
|
|
||||||
|
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car)));
|
||||||
|
console.info('============= END : changeCarOwner ===========');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
8
chaincode/fabcar/typescript/src/index.ts
Normal file
8
chaincode/fabcar/typescript/src/index.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FabCar } from './fabcar';
|
||||||
|
export { FabCar } from './fabcar';
|
||||||
|
|
||||||
|
export const contracts: any[] = [ FabCar ];
|
||||||
16
chaincode/fabcar/typescript/tsconfig.json
Normal file
16
chaincode/fabcar/typescript/tsconfig.json
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "dist",
|
||||||
|
"target": "es2017",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"module": "commonjs",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./src/**/*"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"./src/**/*.spec.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
21
chaincode/fabcar/typescript/tslint.json
Normal file
21
chaincode/fabcar/typescript/tslint.json
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"defaultSeverity": "error",
|
||||||
|
"extends": [
|
||||||
|
"tslint:recommended"
|
||||||
|
],
|
||||||
|
"jsRules": {},
|
||||||
|
"rules": {
|
||||||
|
"indent": [true, "spaces", 4],
|
||||||
|
"linebreak-style": [true, "LF"],
|
||||||
|
"quotemark": [true, "single"],
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"curly": true,
|
||||||
|
"triple-equals": true,
|
||||||
|
"no-string-throw": true,
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"object-literal-key-quotes": [true, "as-needed"]
|
||||||
|
},
|
||||||
|
"rulesDirectory": []
|
||||||
|
}
|
||||||
|
|
@ -1,20 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
SPDX-License-Identifier: Apache-2.0
|
||||||
or more contributor license agreements. See the NOTICE file
|
|
||||||
distributed with this work for additional information
|
|
||||||
regarding copyright ownership. The ASF licenses this file
|
|
||||||
to you 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ====CHAINCODE EXECUTION SAMPLES (CLI) ==================
|
// ====CHAINCODE EXECUTION SAMPLES (CLI) ==================
|
||||||
|
|
@ -36,6 +21,9 @@ under the License.
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","tom"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","tom"]}'
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"tom\"}}"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"tom\"}}"]}'
|
||||||
|
|
||||||
|
// Rich Query with Pagination (Only supported if CouchDB is used as state database):
|
||||||
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesWithPagination","{\"selector\":{\"owner\":\"tom\"}}","3",""]}'
|
||||||
|
|
||||||
// INDEXES TO SUPPORT COUCHDB RICH QUERIES
|
// INDEXES TO SUPPORT COUCHDB RICH QUERIES
|
||||||
//
|
//
|
||||||
// Indexes in CouchDB are required in order to make JSON queries efficient and are required for
|
// Indexes in CouchDB are required in order to make JSON queries efficient and are required for
|
||||||
|
|
@ -73,23 +61,15 @@ under the License.
|
||||||
// http://127.0.0.1:5984/
|
// http://127.0.0.1:5984/
|
||||||
|
|
||||||
// Index for docType, owner.
|
// Index for docType, owner.
|
||||||
// Note that docType and owner fields must be prefixed with the "data" wrapper
|
|
||||||
//
|
|
||||||
// Index definition for use with Fauxton interface
|
|
||||||
// {"index":{"fields":["data.docType","data.owner"]},"ddoc":"indexOwnerDoc", "name":"indexOwner","type":"json"}
|
|
||||||
//
|
//
|
||||||
// Example curl command line to define index in the CouchDB channel_chaincode database
|
// Example curl command line to define index in the CouchDB channel_chaincode database
|
||||||
// curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[\"data.docType\",\"data.owner\"]},\"name\":\"indexOwner\",\"ddoc\":\"indexOwnerDoc\",\"type\":\"json\"}" http://hostname:port/myc1_marbles/_index
|
// curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[\"docType\",\"owner\"]},\"name\":\"indexOwner\",\"ddoc\":\"indexOwnerDoc\",\"type\":\"json\"}" http://hostname:port/myc1_marbles/_index
|
||||||
//
|
//
|
||||||
|
|
||||||
// Index for docType, owner, size (descending order).
|
// Index for docType, owner, size (descending order).
|
||||||
// Note that docType, owner and size fields must be prefixed with the "data" wrapper
|
|
||||||
//
|
|
||||||
// Index definition for use with Fauxton interface
|
|
||||||
// {"index":{"fields":[{"data.size":"desc"},{"data.docType":"desc"},{"data.owner":"desc"}]},"ddoc":"indexSizeSortDoc", "name":"indexSizeSortDesc","type":"json"}
|
|
||||||
//
|
//
|
||||||
// Example curl command line to define index in the CouchDB channel_chaincode database
|
// Example curl command line to define index in the CouchDB channel_chaincode database
|
||||||
// curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[{\"data.size\":\"desc\"},{\"data.docType\":\"desc\"},{\"data.owner\":\"desc\"}]},\"ddoc\":\"indexSizeSortDoc\", \"name\":\"indexSizeSortDesc\",\"type\":\"json\"}" http://hostname:port/myc1_marbles/_index
|
// curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[{\"size\":\"desc\"},{\"docType\":\"desc\"},{\"owner\":\"desc\"}]},\"ddoc\":\"indexSizeSortDoc\", \"name\":\"indexSizeSortDesc\",\"type\":\"json\"}" http://hostname:port/myc1_marbles/_index
|
||||||
|
|
||||||
// Rich Query with index design doc and index name specified (Only supported if CouchDB is used as state database):
|
// Rich Query with index design doc and index name specified (Only supported if CouchDB is used as state database):
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":\"marble\",\"owner\":\"tom\"}, \"use_index\":[\"_design/indexOwnerDoc\", \"indexOwner\"]}"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":\"marble\",\"owner\":\"tom\"}, \"use_index\":[\"_design/indexOwnerDoc\", \"indexOwner\"]}"]}'
|
||||||
|
|
@ -164,6 +144,10 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
|
||||||
return t.getHistoryForMarble(stub, args)
|
return t.getHistoryForMarble(stub, args)
|
||||||
} else if function == "getMarblesByRange" { //get marbles based on range query
|
} else if function == "getMarblesByRange" { //get marbles based on range query
|
||||||
return t.getMarblesByRange(stub, args)
|
return t.getMarblesByRange(stub, args)
|
||||||
|
} else if function == "getMarblesByRangeWithPagination" {
|
||||||
|
return t.getMarblesByRangeWithPagination(stub, args)
|
||||||
|
} else if function == "queryMarblesWithPagination" {
|
||||||
|
return t.queryMarblesWithPagination(stub, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("invoke did not find func: " + function) //error
|
fmt.Println("invoke did not find func: " + function) //error
|
||||||
|
|
@ -360,6 +344,59 @@ func (t *SimpleChaincode) transferMarble(stub shim.ChaincodeStubInterface, args
|
||||||
return shim.Success(nil)
|
return shim.Success(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================================
|
||||||
|
// constructQueryResponseFromIterator constructs a JSON array containing query results from
|
||||||
|
// a given result iterator
|
||||||
|
// ===========================================================================================
|
||||||
|
func constructQueryResponseFromIterator(resultsIterator shim.StateQueryIteratorInterface) (*bytes.Buffer, error) {
|
||||||
|
// buffer is a JSON array containing QueryResults
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
buffer.WriteString("[")
|
||||||
|
|
||||||
|
bArrayMemberAlreadyWritten := false
|
||||||
|
for resultsIterator.HasNext() {
|
||||||
|
queryResponse, err := resultsIterator.Next()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Add a comma before array members, suppress it for the first array member
|
||||||
|
if bArrayMemberAlreadyWritten == true {
|
||||||
|
buffer.WriteString(",")
|
||||||
|
}
|
||||||
|
buffer.WriteString("{\"Key\":")
|
||||||
|
buffer.WriteString("\"")
|
||||||
|
buffer.WriteString(queryResponse.Key)
|
||||||
|
buffer.WriteString("\"")
|
||||||
|
|
||||||
|
buffer.WriteString(", \"Record\":")
|
||||||
|
// Record is a JSON object, so we write as-is
|
||||||
|
buffer.WriteString(string(queryResponse.Value))
|
||||||
|
buffer.WriteString("}")
|
||||||
|
bArrayMemberAlreadyWritten = true
|
||||||
|
}
|
||||||
|
buffer.WriteString("]")
|
||||||
|
|
||||||
|
return &buffer, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================================================
|
||||||
|
// addPaginationMetadataToQueryResults adds QueryResponseMetadata, which contains pagination
|
||||||
|
// info, to the constructed query results
|
||||||
|
// ===========================================================================================
|
||||||
|
func addPaginationMetadataToQueryResults(buffer *bytes.Buffer, responseMetadata *pb.QueryResponseMetadata) *bytes.Buffer {
|
||||||
|
|
||||||
|
buffer.WriteString("[{\"ResponseMetadata\":{\"RecordsCount\":")
|
||||||
|
buffer.WriteString("\"")
|
||||||
|
buffer.WriteString(fmt.Sprintf("%v", responseMetadata.FetchedRecordsCount))
|
||||||
|
buffer.WriteString("\"")
|
||||||
|
buffer.WriteString(", \"Bookmark\":")
|
||||||
|
buffer.WriteString("\"")
|
||||||
|
buffer.WriteString(responseMetadata.Bookmark)
|
||||||
|
buffer.WriteString("\"}}]")
|
||||||
|
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================================
|
// ===========================================================================================
|
||||||
// getMarblesByRange performs a range query based on the start and end keys provided.
|
// getMarblesByRange performs a range query based on the start and end keys provided.
|
||||||
|
|
||||||
|
|
@ -386,32 +423,10 @@ func (t *SimpleChaincode) getMarblesByRange(stub shim.ChaincodeStubInterface, ar
|
||||||
}
|
}
|
||||||
defer resultsIterator.Close()
|
defer resultsIterator.Close()
|
||||||
|
|
||||||
// buffer is a JSON array containing QueryResults
|
buffer, err := constructQueryResponseFromIterator(resultsIterator)
|
||||||
var buffer bytes.Buffer
|
|
||||||
buffer.WriteString("[")
|
|
||||||
|
|
||||||
bArrayMemberAlreadyWritten := false
|
|
||||||
for resultsIterator.HasNext() {
|
|
||||||
queryResponse, err := resultsIterator.Next()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return shim.Error(err.Error())
|
return shim.Error(err.Error())
|
||||||
}
|
}
|
||||||
// Add a comma before array members, suppress it for the first array member
|
|
||||||
if bArrayMemberAlreadyWritten == true {
|
|
||||||
buffer.WriteString(",")
|
|
||||||
}
|
|
||||||
buffer.WriteString("{\"Key\":")
|
|
||||||
buffer.WriteString("\"")
|
|
||||||
buffer.WriteString(queryResponse.Key)
|
|
||||||
buffer.WriteString("\"")
|
|
||||||
|
|
||||||
buffer.WriteString(", \"Record\":")
|
|
||||||
// Record is a JSON object, so we write as-is
|
|
||||||
buffer.WriteString(string(queryResponse.Value))
|
|
||||||
buffer.WriteString("}")
|
|
||||||
bArrayMemberAlreadyWritten = true
|
|
||||||
}
|
|
||||||
buffer.WriteString("]")
|
|
||||||
|
|
||||||
fmt.Printf("- getMarblesByRange queryResult:\n%s\n", buffer.String())
|
fmt.Printf("- getMarblesByRange queryResult:\n%s\n", buffer.String())
|
||||||
|
|
||||||
|
|
@ -554,38 +569,126 @@ func getQueryResultForQueryString(stub shim.ChaincodeStubInterface, queryString
|
||||||
}
|
}
|
||||||
defer resultsIterator.Close()
|
defer resultsIterator.Close()
|
||||||
|
|
||||||
// buffer is a JSON array containing QueryRecords
|
buffer, err := constructQueryResponseFromIterator(resultsIterator)
|
||||||
var buffer bytes.Buffer
|
|
||||||
buffer.WriteString("[")
|
|
||||||
|
|
||||||
bArrayMemberAlreadyWritten := false
|
|
||||||
for resultsIterator.HasNext() {
|
|
||||||
queryResponse, err := resultsIterator.Next()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Add a comma before array members, suppress it for the first array member
|
|
||||||
if bArrayMemberAlreadyWritten == true {
|
|
||||||
buffer.WriteString(",")
|
|
||||||
}
|
|
||||||
buffer.WriteString("{\"Key\":")
|
|
||||||
buffer.WriteString("\"")
|
|
||||||
buffer.WriteString(queryResponse.Key)
|
|
||||||
buffer.WriteString("\"")
|
|
||||||
|
|
||||||
buffer.WriteString(", \"Record\":")
|
|
||||||
// Record is a JSON object, so we write as-is
|
|
||||||
buffer.WriteString(string(queryResponse.Value))
|
|
||||||
buffer.WriteString("}")
|
|
||||||
bArrayMemberAlreadyWritten = true
|
|
||||||
}
|
|
||||||
buffer.WriteString("]")
|
|
||||||
|
|
||||||
fmt.Printf("- getQueryResultForQueryString queryResult:\n%s\n", buffer.String())
|
fmt.Printf("- getQueryResultForQueryString queryResult:\n%s\n", buffer.String())
|
||||||
|
|
||||||
return buffer.Bytes(), nil
|
return buffer.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====== Pagination =========================================================================
|
||||||
|
// Pagination provides a method to retrieve records with a defined pagesize and
|
||||||
|
// start point (bookmark). An empty string bookmark defines the first "page" of a query
|
||||||
|
// result. Paginated queries return a bookmark that can be used in
|
||||||
|
// the next query to retrieve the next page of results. Paginated queries extend
|
||||||
|
// rich queries and range queries to include a pagesize and bookmark.
|
||||||
|
//
|
||||||
|
// Two examples are provided in this example. The first is getMarblesByRangeWithPagination
|
||||||
|
// which executes a paginated range query.
|
||||||
|
// The second example is a paginated query for rich ad-hoc queries.
|
||||||
|
// =========================================================================================
|
||||||
|
|
||||||
|
// ====== Example: Pagination with Range Query ===============================================
|
||||||
|
// getMarblesByRangeWithPagination performs a range query based on the start & end key,
|
||||||
|
// page size and a bookmark.
|
||||||
|
|
||||||
|
// The number of fetched records will be equal to or lesser than the page size.
|
||||||
|
// Paginated range queries are only valid for read only transactions.
|
||||||
|
// ===========================================================================================
|
||||||
|
func (t *SimpleChaincode) getMarblesByRangeWithPagination(stub shim.ChaincodeStubInterface, args []string) pb.Response {
|
||||||
|
|
||||||
|
if len(args) < 4 {
|
||||||
|
return shim.Error("Incorrect number of arguments. Expecting 4")
|
||||||
|
}
|
||||||
|
|
||||||
|
startKey := args[0]
|
||||||
|
endKey := args[1]
|
||||||
|
//return type of ParseInt is int64
|
||||||
|
pageSize, err := strconv.ParseInt(args[2], 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return shim.Error(err.Error())
|
||||||
|
}
|
||||||
|
bookmark := args[3]
|
||||||
|
|
||||||
|
resultsIterator, responseMetadata, err := stub.GetStateByRangeWithPagination(startKey, endKey, int32(pageSize), bookmark)
|
||||||
|
if err != nil {
|
||||||
|
return shim.Error(err.Error())
|
||||||
|
}
|
||||||
|
defer resultsIterator.Close()
|
||||||
|
|
||||||
|
buffer, err := constructQueryResponseFromIterator(resultsIterator)
|
||||||
|
if err != nil {
|
||||||
|
return shim.Error(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferWithPaginationInfo := addPaginationMetadataToQueryResults(buffer, responseMetadata)
|
||||||
|
|
||||||
|
fmt.Printf("- getMarblesByRange queryResult:\n%s\n", bufferWithPaginationInfo.String())
|
||||||
|
|
||||||
|
return shim.Success(buffer.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== Example: Pagination with Ad hoc Rich Query ========================================================
|
||||||
|
// queryMarblesWithPagination uses a query string, page size and a bookmark to perform a query
|
||||||
|
// for marbles. Query string matching state database syntax is passed in and executed as is.
|
||||||
|
// The number of fetched records would be equal to or lesser than the specified page size.
|
||||||
|
// Supports ad hoc queries that can be defined at runtime by the client.
|
||||||
|
// If this is not desired, follow the queryMarblesForOwner example for parameterized queries.
|
||||||
|
// Only available on state databases that support rich query (e.g. CouchDB)
|
||||||
|
// Paginated queries are only valid for read only transactions.
|
||||||
|
// =========================================================================================
|
||||||
|
func (t *SimpleChaincode) queryMarblesWithPagination(stub shim.ChaincodeStubInterface, args []string) pb.Response {
|
||||||
|
|
||||||
|
// 0
|
||||||
|
// "queryString"
|
||||||
|
if len(args) < 3 {
|
||||||
|
return shim.Error("Incorrect number of arguments. Expecting 3")
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString := args[0]
|
||||||
|
//return type of ParseInt is int64
|
||||||
|
pageSize, err := strconv.ParseInt(args[1], 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return shim.Error(err.Error())
|
||||||
|
}
|
||||||
|
bookmark := args[2]
|
||||||
|
|
||||||
|
queryResults, err := getQueryResultForQueryStringWithPagination(stub, queryString, int32(pageSize), bookmark)
|
||||||
|
if err != nil {
|
||||||
|
return shim.Error(err.Error())
|
||||||
|
}
|
||||||
|
return shim.Success(queryResults)
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================================
|
||||||
|
// getQueryResultForQueryStringWithPagination executes the passed in query string with
|
||||||
|
// pagination info. Result set is built and returned as a byte array containing the JSON results.
|
||||||
|
// =========================================================================================
|
||||||
|
func getQueryResultForQueryStringWithPagination(stub shim.ChaincodeStubInterface, queryString string, pageSize int32, bookmark string) ([]byte, error) {
|
||||||
|
|
||||||
|
fmt.Printf("- getQueryResultForQueryString queryString:\n%s\n", queryString)
|
||||||
|
|
||||||
|
resultsIterator, responseMetadata, err := stub.GetQueryResultWithPagination(queryString, pageSize, bookmark)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resultsIterator.Close()
|
||||||
|
|
||||||
|
buffer, err := constructQueryResponseFromIterator(resultsIterator)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferWithPaginationInfo := addPaginationMetadataToQueryResults(buffer, responseMetadata)
|
||||||
|
|
||||||
|
fmt.Printf("- getQueryResultForQueryString queryResult:\n%s\n", bufferWithPaginationInfo.String())
|
||||||
|
|
||||||
|
return buffer.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *SimpleChaincode) getHistoryForMarble(stub shim.ChaincodeStubInterface, args []string) pb.Response {
|
func (t *SimpleChaincode) getHistoryForMarble(stub shim.ChaincodeStubInterface, args []string) pb.Response {
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,15 @@
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["readMarble","marble1"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["readMarble","marble1"]}'
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["getMarblesByRange","marble1","marble3"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["getMarblesByRange","marble1","marble3"]}'
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["getHistoryForMarble","marble1"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["getHistoryForMarble","marble1"]}'
|
||||||
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["getMarblesByRangeWithPagination","marble1","marble3","3",""]}'
|
||||||
|
|
||||||
// Rich Query (Only supported if CouchDB is used as state database):
|
// Rich Query (Only supported if CouchDB is used as state database):
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","tom"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","tom"]}'
|
||||||
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"tom\"}}"]}'
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"tom\"}}"]}'
|
||||||
|
|
||||||
|
// Rich Query with Pagination (Only supported if CouchDB is used as state database):
|
||||||
|
// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesWithPagination","{\"selector\":{\"owner\":\"tom\"}}","3",""]}'
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
const shim = require('fabric-shim');
|
const shim = require('fabric-shim');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
@ -404,6 +408,74 @@ let Chaincode = class {
|
||||||
|
|
||||||
return Buffer.from(JSON.stringify(results));
|
return Buffer.from(JSON.stringify(results));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====== Pagination =========================================================================
|
||||||
|
// Pagination provides a method to retrieve records with a defined pagesize and
|
||||||
|
// start point (bookmark). An empty string bookmark defines the first "page" of a query
|
||||||
|
// result. Paginated queries return a bookmark that can be used in
|
||||||
|
// the next query to retrieve the next page of results. Paginated queries extend
|
||||||
|
// rich queries and range queries to include a pagesize and bookmark.
|
||||||
|
//
|
||||||
|
// Two examples are provided in this example. The first is getMarblesByRangeWithPagination
|
||||||
|
// which executes a paginated range query.
|
||||||
|
// The second example is a paginated query for rich ad-hoc queries.
|
||||||
|
// =========================================================================================
|
||||||
|
|
||||||
|
// ====== Example: Pagination with Range Query ===============================================
|
||||||
|
// getMarblesByRangeWithPagination performs a range query based on the start & end key,
|
||||||
|
// page size and a bookmark.
|
||||||
|
//
|
||||||
|
// The number of fetched records will be equal to or lesser than the page size.
|
||||||
|
// Paginated range queries are only valid for read only transactions.
|
||||||
|
// ===========================================================================================
|
||||||
|
async getMarblesByRangeWithPagination(stub, args, thisClass) {
|
||||||
|
if (args.length < 2) {
|
||||||
|
throw new Error('Incorrect number of arguments. Expecting 2');
|
||||||
|
}
|
||||||
|
const startKey = args[0];
|
||||||
|
const endKey = args[1];
|
||||||
|
|
||||||
|
const pageSize = parseInt(args[2], 10);
|
||||||
|
const bookmark = args[3];
|
||||||
|
|
||||||
|
const { iterator, metadata } = await stub.getStateByRangeWithPagination(startKey, endKey, pageSize, bookmark);
|
||||||
|
const getAllResults = thisClass['getAllResults'];
|
||||||
|
const results = await getAllResults(iterator, false);
|
||||||
|
// use RecordsCount and Bookmark to keep consistency with the go sample
|
||||||
|
results.ResponseMetadata = {
|
||||||
|
RecordsCount: metadata.fetched_records_count,
|
||||||
|
Bookmark: metadata.bookmark,
|
||||||
|
};
|
||||||
|
return Buffer.from(JSON.stringify(results));
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================================
|
||||||
|
// getQueryResultForQueryStringWithPagination executes the passed in query string with
|
||||||
|
// pagination info. Result set is built and returned as a byte array containing the JSON results.
|
||||||
|
// =========================================================================================
|
||||||
|
async queryMarblesWithPagination(stub, args, thisClass) {
|
||||||
|
|
||||||
|
// 0
|
||||||
|
// "queryString"
|
||||||
|
if (args.length < 3) {
|
||||||
|
return shim.Error("Incorrect number of arguments. Expecting 3")
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryString = args[0];
|
||||||
|
const pageSize = parseInt(args[2], 10);
|
||||||
|
const bookmark = args[3];
|
||||||
|
|
||||||
|
const { iterator, metadata } = await stub.GetQueryResultWithPagination(queryString, pageSize, bookmark);
|
||||||
|
const getAllResults = thisClass['getAllResults'];
|
||||||
|
const results = await getAllResults(iterator, false);
|
||||||
|
// use RecordsCount and Bookmark to keep consistency with the go sample
|
||||||
|
results.ResponseMetadata = {
|
||||||
|
RecordsCount: metadata.fetched_records_count,
|
||||||
|
Bookmark: metadata.bookmark,
|
||||||
|
};
|
||||||
|
|
||||||
|
return Buffer.from(JSON.stringify(results));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
shim.start(new Chaincode());
|
shim.start(new Chaincode());
|
||||||
|
|
|
||||||
8
commercial-paper/.gitignore
vendored
Normal file
8
commercial-paper/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
organization/magnetocorp/application/node_modules/
|
||||||
|
organization/magnetocorp/contract/node_modules/
|
||||||
|
organization/magnetocorp/identity/user/
|
||||||
|
organization/digibank/application/node_modules/
|
||||||
|
organization/digibank/contract/node_modules/
|
||||||
|
organization/digibank/identity/user/
|
||||||
|
package-lock.json
|
||||||
|
.vscode
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
mocha: true
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 8,
|
||||||
|
sourceType: 'script'
|
||||||
|
},
|
||||||
|
extends: "eslint:recommended",
|
||||||
|
rules: {
|
||||||
|
indent: ['error', 4],
|
||||||
|
'linebreak-style': ['error', 'unix'],
|
||||||
|
quotes: ['error', 'single'],
|
||||||
|
semi: ['error', 'always'],
|
||||||
|
'no-unused-vars': ['error', { args: 'none' }],
|
||||||
|
'no-console': 'off',
|
||||||
|
curly: 'error',
|
||||||
|
eqeqeq: 'error',
|
||||||
|
'no-throw-literal': 'error',
|
||||||
|
strict: 'error',
|
||||||
|
'no-var': 'error',
|
||||||
|
'dot-notation': 'error',
|
||||||
|
'no-tabs': 'error',
|
||||||
|
'no-trailing-spaces': 'error',
|
||||||
|
'no-use-before-define': 'error',
|
||||||
|
'no-useless-call': 'error',
|
||||||
|
'no-with': 'error',
|
||||||
|
'operator-linebreak': 'error',
|
||||||
|
yoda: 'error',
|
||||||
|
'quote-props': ['error', 'as-needed']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Bring key classes into scope, most importantly Fabric SDK network class
|
||||||
|
const fs = require('fs');
|
||||||
|
const { FileSystemWallet, X509WalletMixin } = require('fabric-network');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const fixtures = path.resolve(__dirname, '../../../../basic-network');
|
||||||
|
|
||||||
|
// A wallet stores a collection of identities
|
||||||
|
const wallet = new FileSystemWallet('../identity/user/balaji/wallet');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
|
||||||
|
// Main try/catch block
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Identity to credentials to be stored in the wallet
|
||||||
|
const credPath = path.join(fixtures, '/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com');
|
||||||
|
const cert = fs.readFileSync(path.join(credPath, '/msp/signcerts/Admin@org1.example.com-cert.pem')).toString();
|
||||||
|
const key = fs.readFileSync(path.join(credPath, '/msp/keystore/cd96d5260ad4757551ed4a5a991e62130f8008a0bf996e4e4b84cd097a747fec_sk')).toString();
|
||||||
|
|
||||||
|
// Load credentials into wallet
|
||||||
|
const identityLabel = 'Admin@org1.example.com';
|
||||||
|
const identity = X509WalletMixin.createIdentity('Org1MSP', cert, key);
|
||||||
|
|
||||||
|
await wallet.import(identityLabel, identity);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Error adding to wallet. ${error}`);
|
||||||
|
console.log(error.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(() => {
|
||||||
|
console.log('done');
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log(e);
|
||||||
|
console.log(e.stack);
|
||||||
|
process.exit(-1);
|
||||||
|
});
|
||||||
102
commercial-paper/organization/digibank/application/buy.js
Normal file
102
commercial-paper/organization/digibank/application/buy.js
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This application has 6 basic steps:
|
||||||
|
* 1. Select an identity from a wallet
|
||||||
|
* 2. Connect to network gateway
|
||||||
|
* 3. Access PaperNet network
|
||||||
|
* 4. Construct request to issue commercial paper
|
||||||
|
* 5. Submit transaction
|
||||||
|
* 6. Process response
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Bring key classes into scope, most importantly Fabric SDK network class
|
||||||
|
const fs = require('fs');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
const { FileSystemWallet, Gateway } = require('fabric-network');
|
||||||
|
const CommercialPaper = require('../contract/lib/paper.js');
|
||||||
|
|
||||||
|
// A wallet stores a collection of identities for use
|
||||||
|
const wallet = new FileSystemWallet('../identity/user/balaji/wallet');
|
||||||
|
|
||||||
|
// Main program function
|
||||||
|
async function main() {
|
||||||
|
|
||||||
|
// A gateway defines the peers used to access Fabric networks
|
||||||
|
const gateway = new Gateway();
|
||||||
|
|
||||||
|
// Main try/catch block
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Specify userName for network access
|
||||||
|
// const userName = 'isabella.issuer@magnetocorp.com';
|
||||||
|
const userName = 'Admin@org1.example.com';
|
||||||
|
|
||||||
|
// Load connection profile; will be used to locate a gateway
|
||||||
|
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8'));
|
||||||
|
|
||||||
|
// Set connection options; identity and wallet
|
||||||
|
let connectionOptions = {
|
||||||
|
identity: userName,
|
||||||
|
wallet: wallet,
|
||||||
|
discovery: { enabled:false, asLocalhost: true }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Connect to gateway using application specified parameters
|
||||||
|
console.log('Connect to Fabric gateway.');
|
||||||
|
|
||||||
|
await gateway.connect(connectionProfile, connectionOptions);
|
||||||
|
|
||||||
|
// Access PaperNet network
|
||||||
|
console.log('Use network channel: mychannel.');
|
||||||
|
|
||||||
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
||||||
|
// Get addressability to commercial paper contract
|
||||||
|
console.log('Use org.papernet.commercialpaper smart contract.');
|
||||||
|
|
||||||
|
const contract = await network.getContract('papercontract', 'org.papernet.commercialpaper');
|
||||||
|
|
||||||
|
// buy commercial paper
|
||||||
|
console.log('Submit commercial paper buy transaction.');
|
||||||
|
|
||||||
|
const buyResponse = await contract.submitTransaction('buy', 'MagnetoCorp', '00001', 'MagnetoCorp', 'DigiBank', '4900000', '2020-05-31');
|
||||||
|
|
||||||
|
// process response
|
||||||
|
console.log('Process buy transaction response.');
|
||||||
|
|
||||||
|
let paper = CommercialPaper.fromBuffer(buyResponse);
|
||||||
|
|
||||||
|
console.log(`${paper.issuer} commercial paper : ${paper.paperNumber} successfully purchased by ${paper.owner}`);
|
||||||
|
console.log('Transaction complete.');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
console.log(`Error processing transaction. ${error}`);
|
||||||
|
console.log(error.stack);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
// Disconnect from the gateway
|
||||||
|
console.log('Disconnect from Fabric gateway.')
|
||||||
|
gateway.disconnect();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main().then(() => {
|
||||||
|
|
||||||
|
console.log('Buy program complete.');
|
||||||
|
|
||||||
|
}).catch((e) => {
|
||||||
|
|
||||||
|
console.log('Buy program exception.');
|
||||||
|
console.log(e);
|
||||||
|
console.log(e.stack);
|
||||||
|
process.exit(-1);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "nodejs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "buy.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "rm -rf _idwallet && node addToWallet.js && node buy.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"fabric-network": "^1.4.0-beta",
|
||||||
|
"fabric-client": "^1.4.0-beta",
|
||||||
|
"js-yaml": "^3.12.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^5.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
101
commercial-paper/organization/digibank/application/redeem.js
Normal file
101
commercial-paper/organization/digibank/application/redeem.js
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This application has 6 basic steps:
|
||||||
|
* 1. Select an identity from a wallet
|
||||||
|
* 2. Connect to network gateway
|
||||||
|
* 3. Access PaperNet network
|
||||||
|
* 4. Construct request to issue commercial paper
|
||||||
|
* 5. Submit transaction
|
||||||
|
* 6. Process response
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Bring key classes into scope, most importantly Fabric SDK network class
|
||||||
|
const fs = require('fs');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
const { FileSystemWallet, Gateway } = require('fabric-network');
|
||||||
|
const CommercialPaper = require('../contract/lib/paper.js');
|
||||||
|
|
||||||
|
// A wallet stores a collection of identities for use
|
||||||
|
const wallet = new FileSystemWallet('../identity/user/balaji/wallet');
|
||||||
|
|
||||||
|
// Main program function
|
||||||
|
async function main() {
|
||||||
|
|
||||||
|
// A gateway defines the peers used to access Fabric networks
|
||||||
|
const gateway = new Gateway();
|
||||||
|
|
||||||
|
// Main try/catch block
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Specify userName for network access
|
||||||
|
// const userName = 'isabella.issuer@magnetocorp.com';
|
||||||
|
const userName = 'Admin@org1.example.com';
|
||||||
|
|
||||||
|
// Load connection profile; will be used to locate a gateway
|
||||||
|
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8'));
|
||||||
|
|
||||||
|
// Set connection options; identity and wallet
|
||||||
|
let connectionOptions = {
|
||||||
|
identity: userName,
|
||||||
|
wallet: wallet,
|
||||||
|
discovery: { enabled:false, asLocalhost: true }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Connect to gateway using application specified parameters
|
||||||
|
console.log('Connect to Fabric gateway.');
|
||||||
|
|
||||||
|
await gateway.connect(connectionProfile, connectionOptions);
|
||||||
|
|
||||||
|
// Access PaperNet network
|
||||||
|
console.log('Use network channel: mychannel.');
|
||||||
|
|
||||||
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
||||||
|
// Get addressability to commercial paper contract
|
||||||
|
console.log('Use org.papernet.commercialpaper smart contract.');
|
||||||
|
|
||||||
|
const contract = await network.getContract('papercontract', 'org.papernet.commercialpaper');
|
||||||
|
|
||||||
|
// redeem commercial paper
|
||||||
|
console.log('Submit commercial paper redeem transaction.');
|
||||||
|
|
||||||
|
const redeemResponse = await contract.submitTransaction('redeem', 'MagnetoCorp', '00001', 'DigiBank', '2020-11-30');
|
||||||
|
|
||||||
|
// process response
|
||||||
|
console.log('Process redeem transaction response.');
|
||||||
|
|
||||||
|
let paper = CommercialPaper.fromBuffer(redeemResponse);
|
||||||
|
|
||||||
|
console.log(`${paper.issuer} commercial paper : ${paper.paperNumber} successfully redeemed with ${paper.owner}`);
|
||||||
|
console.log('Transaction complete.');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
console.log(`Error processing transaction. ${error}`);
|
||||||
|
console.log(error.stack);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
// Disconnect from the gateway
|
||||||
|
console.log('Disconnect from Fabric gateway.')
|
||||||
|
gateway.disconnect();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main().then(() => {
|
||||||
|
|
||||||
|
console.log('Redeem program complete.');
|
||||||
|
|
||||||
|
}).catch((e) => {
|
||||||
|
|
||||||
|
console.log('Redeem program exception.');
|
||||||
|
console.log(e);
|
||||||
|
console.log(e.stack);
|
||||||
|
process.exit(-1);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
#
|
||||||
|
# Copyright IBM Corp All Rights Reserved
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
networks:
|
||||||
|
basic:
|
||||||
|
external:
|
||||||
|
name: net_basic
|
||||||
|
|
||||||
|
services:
|
||||||
|
cliDigiBank:
|
||||||
|
container_name: cliDigiBank
|
||||||
|
image: hyperledger/fabric-tools
|
||||||
|
tty: true
|
||||||
|
environment:
|
||||||
|
- GOPATH=/opt/gopath
|
||||||
|
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
|
||||||
|
- CORE_LOGGING_LEVEL=info
|
||||||
|
- CORE_PEER_ID=cli
|
||||||
|
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||||
|
- CORE_PEER_LOCALMSPID=Org1MSP
|
||||||
|
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||||
|
- CORE_CHAINCODE_KEEPALIVE=10
|
||||||
|
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
|
||||||
|
command: /bin/bash
|
||||||
|
volumes:
|
||||||
|
- /var/run/:/host/var/run/
|
||||||
|
- ./../../../../organization/digibank:/opt/gopath/src/github.com/
|
||||||
|
- ./../../../../../basic-network/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
|
||||||
|
networks:
|
||||||
|
- basic
|
||||||
|
#depends_on:
|
||||||
|
# - orderer.example.com
|
||||||
|
# - peer0.org1.example.com
|
||||||
|
# - couchdb
|
||||||
25
commercial-paper/organization/digibank/configuration/cli/monitordocker.sh
Executable file
25
commercial-paper/organization/digibank/configuration/cli/monitordocker.sh
Executable file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script uses the logspout and http stream tools to let you watch the docker containers
|
||||||
|
# in action.
|
||||||
|
#
|
||||||
|
# More information at https://github.com/gliderlabs/logspout/tree/master/httpstream
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
DOCKER_NETWORK=basicnetwork_basic
|
||||||
|
else
|
||||||
|
DOCKER_NETWORK="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo Starting monitoring on all containers on the network ${DOCKER_NETWORK}
|
||||||
|
|
||||||
|
docker kill logspout 2> /dev/null 1>&2 || true
|
||||||
|
docker rm logspout 2> /dev/null 1>&2 || true
|
||||||
|
|
||||||
|
docker run -d --name="logspout" \
|
||||||
|
--volume=/var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
--publish=127.0.0.1:8000:80 \
|
||||||
|
--network ${DOCKER_NETWORK} \
|
||||||
|
gliderlabs/logspout
|
||||||
|
sleep 3
|
||||||
|
curl http://127.0.0.1:8000/logs
|
||||||
16
commercial-paper/organization/digibank/contract/.editorconfig
Executable file
16
commercial-paper/organization/digibank/contract/.editorconfig
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
coverage
|
||||||
37
commercial-paper/organization/digibank/contract/.eslintrc.js
Normal file
37
commercial-paper/organization/digibank/contract/.eslintrc.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
mocha: true
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 8,
|
||||||
|
sourceType: 'script'
|
||||||
|
},
|
||||||
|
extends: "eslint:recommended",
|
||||||
|
rules: {
|
||||||
|
indent: ['error', 4],
|
||||||
|
'linebreak-style': ['error', 'unix'],
|
||||||
|
quotes: ['error', 'single'],
|
||||||
|
semi: ['error', 'always'],
|
||||||
|
'no-unused-vars': ['error', { args: 'none' }],
|
||||||
|
'no-console': 'off',
|
||||||
|
curly: 'error',
|
||||||
|
eqeqeq: 'error',
|
||||||
|
'no-throw-literal': 'error',
|
||||||
|
strict: 'error',
|
||||||
|
'no-var': 'error',
|
||||||
|
'dot-notation': 'error',
|
||||||
|
'no-tabs': 'error',
|
||||||
|
'no-trailing-spaces': 'error',
|
||||||
|
'no-use-before-define': 'error',
|
||||||
|
'no-useless-call': 'error',
|
||||||
|
'no-with': 'error',
|
||||||
|
'operator-linebreak': 'error',
|
||||||
|
yoda: 'error',
|
||||||
|
'quote-props': ['error', 'as-needed']
|
||||||
|
}
|
||||||
|
};
|
||||||
77
commercial-paper/organization/digibank/contract/.npmignore
Normal file
77
commercial-paper/organization/digibank/contract/.npmignore
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# nuxt.js build output
|
||||||
|
.nuxt
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless
|
||||||
8
commercial-paper/organization/digibank/contract/index.js
Normal file
8
commercial-paper/organization/digibank/contract/index.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const cpcontract = require('./lib/papercontract.js');
|
||||||
|
module.exports.contracts = [cpcontract];
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State class. States have a class, unique key, and a lifecycle current state
|
||||||
|
* the current state is determined by the specific subclass
|
||||||
|
*/
|
||||||
|
class State {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String|Object} class An indentifiable class of the instance
|
||||||
|
* @param {keyParts[]} elements to pull together to make a key for the objects
|
||||||
|
*/
|
||||||
|
constructor(stateClass, keyParts) {
|
||||||
|
this.class = stateClass;
|
||||||
|
this.key = State.makeKey(keyParts);
|
||||||
|
this.currentState = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getClass() {
|
||||||
|
return this.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSplitKey(){
|
||||||
|
return State.splitKey(this.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentState(){
|
||||||
|
return this.currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize() {
|
||||||
|
return State.serialize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert object to buffer containing JSON data serialization
|
||||||
|
* Typically used before putState()ledger API
|
||||||
|
* @param {Object} JSON object to serialize
|
||||||
|
* @return {buffer} buffer with the data to store
|
||||||
|
*/
|
||||||
|
static serialize(object) {
|
||||||
|
return Buffer.from(JSON.stringify(object));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize object into one of a set of supported JSON classes
|
||||||
|
* i.e. Covert serialized data to JSON object
|
||||||
|
* Typically used after getState() ledger API
|
||||||
|
* @param {data} data to deserialize into JSON object
|
||||||
|
* @param (supportedClasses) the set of classes data can be serialized to
|
||||||
|
* @return {json} json with the data to store
|
||||||
|
*/
|
||||||
|
static deserialize(data, supportedClasses) {
|
||||||
|
let json = JSON.parse(data.toString());
|
||||||
|
let objClass = supportedClasses[json.class];
|
||||||
|
if (!objClass) {
|
||||||
|
throw new Error(`Unknown class of ${json.class}`);
|
||||||
|
}
|
||||||
|
let object = new (objClass)(json);
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize object into specific object class
|
||||||
|
* Typically used after getState() ledger API
|
||||||
|
* @param {data} data to deserialize into JSON object
|
||||||
|
* @return {json} json with the data to store
|
||||||
|
*/
|
||||||
|
static deserializeClass(data, objClass) {
|
||||||
|
let json = JSON.parse(data.toString());
|
||||||
|
let object = new (objClass)(json);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join the keyParts to make a unififed string
|
||||||
|
* @param (String[]) keyParts
|
||||||
|
*/
|
||||||
|
static makeKey(keyParts) {
|
||||||
|
return keyParts.map(part => JSON.stringify(part)).join(':');
|
||||||
|
}
|
||||||
|
|
||||||
|
static splitKey(key){
|
||||||
|
return key.split(':');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = State;
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
const State = require('./state.js');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StateList provides a named virtual container for a set of ledger states.
|
||||||
|
* Each state has a unique key which associates it with the container, rather
|
||||||
|
* than the container containing a link to the state. This minimizes collisions
|
||||||
|
* for parallel transactions on different states.
|
||||||
|
*/
|
||||||
|
class StateList {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store Fabric context for subsequent API access, and name of list
|
||||||
|
*/
|
||||||
|
constructor(ctx, listName) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.name = listName;
|
||||||
|
this.supportedClasses = {};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a state to the list. Creates a new state in worldstate with
|
||||||
|
* appropriate composite key. Note that state defines its own key.
|
||||||
|
* State object is serialized before writing.
|
||||||
|
*/
|
||||||
|
async addState(state) {
|
||||||
|
let key = this.ctx.stub.createCompositeKey(this.name, state.getSplitKey());
|
||||||
|
let data = State.serialize(state);
|
||||||
|
await this.ctx.stub.putState(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a state from the list using supplied keys. Form composite
|
||||||
|
* keys to retrieve state from world state. State data is deserialized
|
||||||
|
* into JSON object before being returned.
|
||||||
|
*/
|
||||||
|
async getState(key) {
|
||||||
|
let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
|
||||||
|
let data = await this.ctx.stub.getState(ledgerKey);
|
||||||
|
let state = State.deserialize(data, this.supportedClasses);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a state in the list. Puts the new state in world state with
|
||||||
|
* appropriate composite key. Note that state defines its own key.
|
||||||
|
* A state is serialized before writing. Logic is very similar to
|
||||||
|
* addState() but kept separate becuase it is semantically distinct.
|
||||||
|
*/
|
||||||
|
async updateState(state) {
|
||||||
|
let key = this.ctx.stub.createCompositeKey(this.name, state.getSplitKey());
|
||||||
|
let data = State.serialize(state);
|
||||||
|
await this.ctx.stub.putState(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stores the class for future deserialization */
|
||||||
|
use(stateClass) {
|
||||||
|
this.supportedClasses[stateClass.getClass()] = stateClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = StateList;
|
||||||
102
commercial-paper/organization/digibank/contract/lib/paper.js
Normal file
102
commercial-paper/organization/digibank/contract/lib/paper.js
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Utility class for ledger state
|
||||||
|
const State = require('./../ledger-api/state.js');
|
||||||
|
|
||||||
|
// Enumerate commercial paper state values
|
||||||
|
const cpState = {
|
||||||
|
ISSUED: 1,
|
||||||
|
TRADING: 2,
|
||||||
|
REDEEMED: 3
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CommercialPaper class extends State class
|
||||||
|
* Class will be used by application and smart contract to define a paper
|
||||||
|
*/
|
||||||
|
class CommercialPaper extends State {
|
||||||
|
|
||||||
|
constructor(obj) {
|
||||||
|
super(CommercialPaper.getClass(), [obj.issuer, obj.paperNumber]);
|
||||||
|
Object.assign(this, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic getters and setters
|
||||||
|
*/
|
||||||
|
getIssuer() {
|
||||||
|
return this.issuer;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIssuer(newIssuer) {
|
||||||
|
this.issuer = newIssuer;
|
||||||
|
}
|
||||||
|
|
||||||
|
getOwner() {
|
||||||
|
return this.owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
setOwner(newOwner) {
|
||||||
|
this.owner = newOwner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful methods to encapsulate commercial paper states
|
||||||
|
*/
|
||||||
|
setIssued() {
|
||||||
|
this.currentState = cpState.ISSUED;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTrading() {
|
||||||
|
this.currentState = cpState.TRADING;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRedeemed() {
|
||||||
|
this.currentState = cpState.REDEEMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
isIssued() {
|
||||||
|
return this.currentState === cpState.ISSUED;
|
||||||
|
}
|
||||||
|
|
||||||
|
isTrading() {
|
||||||
|
return this.currentState === cpState.TRADING;
|
||||||
|
}
|
||||||
|
|
||||||
|
isRedeemed() {
|
||||||
|
return this.currentState === cpState.REDEEMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromBuffer(buffer) {
|
||||||
|
return CommercialPaper.deserialize(Buffer.from(JSON.parse(buffer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
toBuffer() {
|
||||||
|
return Buffer.from(JSON.stringify(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize a state data to commercial paper
|
||||||
|
* @param {Buffer} data to form back into the object
|
||||||
|
*/
|
||||||
|
static deserialize(data) {
|
||||||
|
return State.deserializeClass(data, CommercialPaper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a commercial paper object
|
||||||
|
*/
|
||||||
|
static createInstance(issuer, paperNumber, issueDateTime, maturityDateTime, faceValue) {
|
||||||
|
return new CommercialPaper({ issuer, paperNumber, issueDateTime, maturityDateTime, faceValue });
|
||||||
|
}
|
||||||
|
|
||||||
|
static getClass() {
|
||||||
|
return 'org.papernet.commercialpaper';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CommercialPaper;
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Fabric smart contract classes
|
||||||
|
const { Contract, Context } = require('fabric-contract-api');
|
||||||
|
|
||||||
|
// PaperNet specifc classes
|
||||||
|
const CommercialPaper = require('./paper.js');
|
||||||
|
const PaperList = require('./paperlist.js');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom context provides easy access to list of all commercial papers
|
||||||
|
*/
|
||||||
|
class CommercialPaperContext extends Context {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
// All papers are held in a list of papers
|
||||||
|
this.paperList = new PaperList(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define commercial paper smart contract by extending Fabric Contract class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CommercialPaperContract extends Contract {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
// Unique namespace when multiple contracts per chaincode file
|
||||||
|
super('org.papernet.commercialpaper');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define a custom context for commercial paper
|
||||||
|
*/
|
||||||
|
createContext() {
|
||||||
|
return new CommercialPaperContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate to perform any setup of the ledger that might be required.
|
||||||
|
* @param {Context} ctx the transaction context
|
||||||
|
*/
|
||||||
|
async instantiate(ctx) {
|
||||||
|
// No implementation required with this example
|
||||||
|
// It could be where data migration is performed, if necessary
|
||||||
|
console.log('Instantiate the contract');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issue commercial paper
|
||||||
|
*
|
||||||
|
* @param {Context} ctx the transaction context
|
||||||
|
* @param {String} issuer commercial paper issuer
|
||||||
|
* @param {Integer} paperNumber paper number for this issuer
|
||||||
|
* @param {String} issueDateTime paper issue date
|
||||||
|
* @param {String} maturityDateTime paper maturity date
|
||||||
|
* @param {Integer} faceValue face value of paper
|
||||||
|
*/
|
||||||
|
async issue(ctx, issuer, paperNumber, issueDateTime, maturityDateTime, faceValue) {
|
||||||
|
|
||||||
|
// create an instance of the paper
|
||||||
|
let paper = CommercialPaper.createInstance(issuer, paperNumber, issueDateTime, maturityDateTime, faceValue);
|
||||||
|
|
||||||
|
// Smart contract, rather than paper, moves paper into ISSUED state
|
||||||
|
paper.setIssued();
|
||||||
|
|
||||||
|
// Newly issued paper is owned by the issuer
|
||||||
|
paper.setOwner(issuer);
|
||||||
|
|
||||||
|
// Add the paper to the list of all similar commercial papers in the ledger world state
|
||||||
|
await ctx.paperList.addPaper(paper);
|
||||||
|
|
||||||
|
// Must return a serialized paper to caller of smart contract
|
||||||
|
return paper.toBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buy commercial paper
|
||||||
|
*
|
||||||
|
* @param {Context} ctx the transaction context
|
||||||
|
* @param {String} issuer commercial paper issuer
|
||||||
|
* @param {Integer} paperNumber paper number for this issuer
|
||||||
|
* @param {String} currentOwner current owner of paper
|
||||||
|
* @param {String} newOwner new owner of paper
|
||||||
|
* @param {Integer} price price paid for this paper
|
||||||
|
* @param {String} purchaseDateTime time paper was purchased (i.e. traded)
|
||||||
|
*/
|
||||||
|
async buy(ctx, issuer, paperNumber, currentOwner, newOwner, price, purchaseDateTime) {
|
||||||
|
|
||||||
|
// Retrieve the current paper using key fields provided
|
||||||
|
let paperKey = CommercialPaper.makeKey([issuer, paperNumber]);
|
||||||
|
let paper = await ctx.paperList.getPaper(paperKey);
|
||||||
|
|
||||||
|
// Validate current owner
|
||||||
|
if (paper.getOwner() !== currentOwner) {
|
||||||
|
throw new Error('Paper ' + issuer + paperNumber + ' is not owned by ' + currentOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First buy moves state from ISSUED to TRADING
|
||||||
|
if (paper.isIssued()) {
|
||||||
|
paper.setTrading();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check paper is not already REDEEMED
|
||||||
|
if (paper.isTrading()) {
|
||||||
|
paper.setOwner(newOwner);
|
||||||
|
} else {
|
||||||
|
throw new Error('Paper ' + issuer + paperNumber + ' is not trading. Current state = ' + cp.getCurrentState());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the paper
|
||||||
|
await ctx.paperList.updatePaper(paper);
|
||||||
|
return paper.toBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redeem commercial paper
|
||||||
|
*
|
||||||
|
* @param {Context} ctx the transaction context
|
||||||
|
* @param {String} issuer commercial paper issuer
|
||||||
|
* @param {Integer} paperNumber paper number for this issuer
|
||||||
|
* @param {String} redeemingOwner redeeming owner of paper
|
||||||
|
* @param {String} redeemDateTime time paper was redeemed
|
||||||
|
*/
|
||||||
|
async redeem(ctx, issuer, paperNumber, redeemingOwner, redeemDateTime) {
|
||||||
|
|
||||||
|
let paperKey = CommercialPaper.makeKey([issuer, paperNumber]);
|
||||||
|
|
||||||
|
let paper = await ctx.paperList.getPaper(paperKey);
|
||||||
|
|
||||||
|
// Check paper is not REDEEMED
|
||||||
|
if (paper.isRedeemed()) {
|
||||||
|
throw new Error('Paper ' + issuer + paperNumber + ' already redeemed');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that the redeemer owns the commercial paper before redeeming it
|
||||||
|
if (paper.getOwner() === redeemingOwner) {
|
||||||
|
paper.setOwner(paper.getIssuer());
|
||||||
|
paper.setRedeemed();
|
||||||
|
} else {
|
||||||
|
throw new Error('Redeeming owner does not own paper' + issuer + paperNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.paperList.updatePaper(paper);
|
||||||
|
return paper.toBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CommercialPaperContract;
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Utility class for collections of ledger states -- a state list
|
||||||
|
const StateList = require('./../ledger-api/statelist.js');
|
||||||
|
|
||||||
|
const CommercialPaper = require('./paper.js');
|
||||||
|
|
||||||
|
class PaperList extends StateList {
|
||||||
|
|
||||||
|
constructor(ctx) {
|
||||||
|
super(ctx, 'org.papernet.commercialpaperlist');
|
||||||
|
this.use(CommercialPaper);
|
||||||
|
}
|
||||||
|
|
||||||
|
async addPaper(paper) {
|
||||||
|
return this.addState(paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPaper(paperKey) {
|
||||||
|
return this.getState(paperKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
async updatePaper(paper) {
|
||||||
|
return this.updateState(paper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = PaperList;
|
||||||
49
commercial-paper/organization/digibank/contract/package.json
Normal file
49
commercial-paper/organization/digibank/contract/package.json
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
{
|
||||||
|
"name": "papernet-js",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Papernet Contract",
|
||||||
|
"main": "index.js",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8",
|
||||||
|
"npm": ">=5"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint .",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"test": "nyc mocha test --recursive",
|
||||||
|
"start": "fabric-chaincode-node start",
|
||||||
|
"mocha": "mocha test --recursive"
|
||||||
|
},
|
||||||
|
"engineStrict": true,
|
||||||
|
"author": "hyperledger",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"fabric-contract-api": "^1.4.0-snapshot.17",
|
||||||
|
"fabric-shim": "^1.4.0-snapshot.27"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^4.1.2",
|
||||||
|
"chai-as-promised": "^7.1.1",
|
||||||
|
"eslint": "^4.19.1",
|
||||||
|
"mocha": "^5.2.0",
|
||||||
|
"nyc": "^12.0.2",
|
||||||
|
"sinon": "^6.0.0",
|
||||||
|
"sinon-chai": "^3.2.0"
|
||||||
|
},
|
||||||
|
"nyc": {
|
||||||
|
"exclude": [
|
||||||
|
"coverage/**",
|
||||||
|
"test/**"
|
||||||
|
],
|
||||||
|
"reporter": [
|
||||||
|
"text-summary",
|
||||||
|
"html"
|
||||||
|
],
|
||||||
|
"all": true,
|
||||||
|
"check-coverage": true,
|
||||||
|
"statements": 100,
|
||||||
|
"branches": 100,
|
||||||
|
"functions": 100,
|
||||||
|
"lines": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Chaincode = require('../lib/chaincode');
|
||||||
|
const { Stub } = require('fabric-shim');
|
||||||
|
|
||||||
|
require('chai').should();
|
||||||
|
const sinon = require('sinon');
|
||||||
|
|
||||||
|
describe('Chaincode', () => {
|
||||||
|
|
||||||
|
describe('#Init', () => {
|
||||||
|
|
||||||
|
it('should work', async () => {
|
||||||
|
const cc = new Chaincode();
|
||||||
|
const stub = sinon.createStubInstance(Stub);
|
||||||
|
stub.getFunctionAndParameters.returns({ fcn: 'initFunc', params: [] });
|
||||||
|
const res = await cc.Init(stub);
|
||||||
|
res.status.should.equal(Stub.RESPONSE_CODE.OK);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#Invoke', async () => {
|
||||||
|
|
||||||
|
it('should work', async () => {
|
||||||
|
const cc = new Chaincode();
|
||||||
|
const stub = sinon.createStubInstance(Stub);
|
||||||
|
stub.getFunctionAndParameters.returns({ fcn: 'initFunc', params: [] });
|
||||||
|
let res = await cc.Init(stub);
|
||||||
|
res.status.should.equal(Stub.RESPONSE_CODE.OK);
|
||||||
|
stub.getFunctionAndParameters.returns({ fcn: 'invokeFunc', params: [] });
|
||||||
|
res = await cc.Invoke(stub);
|
||||||
|
res.status.should.equal(Stub.RESPONSE_CODE.OK);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,129 @@
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# The network connection profile provides client applications the information about the target
|
||||||
|
# blockchain network that are necessary for the applications to interact with it. These are all
|
||||||
|
# knowledge that must be acquired from out-of-band sources. This file provides such a source.
|
||||||
|
#
|
||||||
|
name: "basic-network"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Any properties with an "x-" prefix will be treated as application-specific, exactly like how naming
|
||||||
|
# in HTTP headers or swagger properties work. The SDK will simply ignore these fields and leave
|
||||||
|
# them for the applications to process. This is a mechanism for different components of an application
|
||||||
|
# to exchange information that are not part of the standard schema described below. In particular,
|
||||||
|
# the "x-type" property with the "hlfv1" value example below is used by Hyperledger Composer to
|
||||||
|
# determine the type of Fabric networks (v0.6 vs. v1.0) it needs to work with.
|
||||||
|
#
|
||||||
|
x-type: "hlfv1"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Describe what the target network is/does.
|
||||||
|
#
|
||||||
|
description: "The basic network"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
|
||||||
|
#
|
||||||
|
version: "1.0"
|
||||||
|
|
||||||
|
#
|
||||||
|
# [Optional]. But most apps would have this section so that channel objects can be constructed
|
||||||
|
# based on the content below. If an app is creating channels, then it likely will not need this
|
||||||
|
# section.
|
||||||
|
#
|
||||||
|
channels:
|
||||||
|
# name of the channel
|
||||||
|
mychannel:
|
||||||
|
# Required. list of orderers designated by the application to use for transactions on this
|
||||||
|
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
|
||||||
|
# operational decisions to share loads from applications among the orderers. The values must
|
||||||
|
# be "names" of orgs defined under "organizations/peers"
|
||||||
|
orderers:
|
||||||
|
- orderer.example.com
|
||||||
|
|
||||||
|
# Required. list of peers from participating orgs
|
||||||
|
peers:
|
||||||
|
peer0.org1.example.com:
|
||||||
|
# [Optional]. will this peer be sent transaction proposals for endorsement? The peer must
|
||||||
|
# have the chaincode installed. The app can also use this property to decide which peers
|
||||||
|
# to send the chaincode install request. Default: true
|
||||||
|
endorsingPeer: true
|
||||||
|
|
||||||
|
# [Optional]. will this peer be sent query proposals? The peer must have the chaincode
|
||||||
|
# installed. The app can also use this property to decide which peers to send the
|
||||||
|
# chaincode install request. Default: true
|
||||||
|
chaincodeQuery: true
|
||||||
|
|
||||||
|
# [Optional]. will this peer be sent query proposals that do not require chaincodes, like
|
||||||
|
# queryBlock(), queryTransaction(), etc. Default: true
|
||||||
|
ledgerQuery: true
|
||||||
|
|
||||||
|
# [Optional]. will this peer be the target of the SDK's listener registration? All peers can
|
||||||
|
# produce events but the app typically only needs to connect to one to listen to events.
|
||||||
|
# Default: true
|
||||||
|
eventSource: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# list of participating organizations in this network
|
||||||
|
#
|
||||||
|
organizations:
|
||||||
|
Org1:
|
||||||
|
mspid: Org1MSP
|
||||||
|
|
||||||
|
peers:
|
||||||
|
- peer0.org1.example.com
|
||||||
|
|
||||||
|
# [Optional]. Certificate Authorities issue certificates for identification purposes in a Fabric based
|
||||||
|
# network. Typically certificates provisioning is done in a separate process outside of the
|
||||||
|
# runtime network. Fabric-CA is a special certificate authority that provides a REST APIs for
|
||||||
|
# dynamic certificate management (enroll, revoke, re-enroll). The following section is only for
|
||||||
|
# Fabric-CA servers.
|
||||||
|
certificateAuthorities:
|
||||||
|
- ca-org1
|
||||||
|
|
||||||
|
#
|
||||||
|
# List of orderers to send transaction and channel create/update requests to. For the time
|
||||||
|
# being only one orderer is needed. If more than one is defined, which one get used by the
|
||||||
|
# SDK is implementation specific. Consult each SDK's documentation for its handling of orderers.
|
||||||
|
#
|
||||||
|
orderers:
|
||||||
|
orderer.example.com:
|
||||||
|
url: grpc://localhost:7050
|
||||||
|
|
||||||
|
# these are standard properties defined by the gRPC library
|
||||||
|
# they will be passed in as-is to gRPC client constructor
|
||||||
|
grpcOptions:
|
||||||
|
ssl-target-name-override: orderer.example.com
|
||||||
|
|
||||||
|
#
|
||||||
|
# List of peers to send various requests to, including endorsement, query
|
||||||
|
# and event listener registration.
|
||||||
|
#
|
||||||
|
peers:
|
||||||
|
peer0.org1.example.com:
|
||||||
|
# this URL is used to send endorsement and query requests
|
||||||
|
url: grpc://localhost:7051
|
||||||
|
|
||||||
|
grpcOptions:
|
||||||
|
ssl-target-name-override: peer0.org1.example.com
|
||||||
|
request-timeout: 120001
|
||||||
|
|
||||||
|
# Fabric-CA is a special kind of Certificate Authority provided by Hyperledger Fabric which allows
|
||||||
|
# certificate management to be done via REST APIs. Application may choose to use a standard
|
||||||
|
# Certificate Authority instead of Fabric-CA, in which case this section would not be specified.
|
||||||
|
#
|
||||||
|
certificateAuthorities:
|
||||||
|
ca-org1:
|
||||||
|
url: http://localhost:7054
|
||||||
|
# the properties specified under this object are passed to the 'http' client verbatim when
|
||||||
|
# making the request to the Fabric-CA server
|
||||||
|
httpOptions:
|
||||||
|
verify: false
|
||||||
|
|
||||||
|
# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
|
||||||
|
# needed to enroll and invoke new users.
|
||||||
|
registrar:
|
||||||
|
- enrollId: admin
|
||||||
|
enrollSecret: adminpw
|
||||||
|
# [Optional] The optional name of the CA.
|
||||||
|
caName: ca-org1
|
||||||
|
|
@ -0,0 +1,225 @@
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# The network connection profile provides client applications the information about the target
|
||||||
|
# blockchain network that are necessary for the applications to interact with it. These are all
|
||||||
|
# knowledge that must be acquired from out-of-band sources. This file provides such a source.
|
||||||
|
#
|
||||||
|
name: "finance-networks"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Any properties with an "x-" prefix will be treated as application-specific, exactly like how naming
|
||||||
|
# in HTTP headers or swagger properties work. The SDK will simply ignore these fields and leave
|
||||||
|
# them for the applications to process. This is a mechanism for different components of an application
|
||||||
|
# to exchange information that are not part of the standard schema described below. In particular,
|
||||||
|
# the "x-type" property with the "hlfv1" value example below is used by Hyperledger Composer to
|
||||||
|
# determine the type of Fabric networks (v0.6 vs. v1.0) it needs to work with.
|
||||||
|
#
|
||||||
|
x-type: "hlfv1"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Describe what the target network is/does.
|
||||||
|
#
|
||||||
|
description: "A gateway connection file for the PaperNet networks"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
|
||||||
|
#
|
||||||
|
version: "1.0"
|
||||||
|
|
||||||
|
#
|
||||||
|
# The client section is SDK-specific. The sample below is for the node.js SDK
|
||||||
|
#
|
||||||
|
#client:
|
||||||
|
# Which organization does this application instance belong to? The value must be the name of an org
|
||||||
|
# defined under "organizations"
|
||||||
|
#organization: Org1
|
||||||
|
|
||||||
|
# Some SDKs support pluggable KV stores, the properties under "credentialStore"
|
||||||
|
# are implementation specific
|
||||||
|
#credentialStore:
|
||||||
|
# [Optional]. Specific to FileKeyValueStore.js or similar implementations in other SDKs. Can be others
|
||||||
|
# if using an alternative impl. For instance, CouchDBKeyValueStore.js would require an object
|
||||||
|
# here for properties like url, db name, etc.
|
||||||
|
#path: "/tmp/hfc-kvs"
|
||||||
|
|
||||||
|
# [Optional]. Specific to the CryptoSuite implementation. Software-based implementations like
|
||||||
|
# CryptoSuite_ECDSA_AES.js in node SDK requires a key store. PKCS#11 based implementations does
|
||||||
|
# not.
|
||||||
|
#cryptoStore:
|
||||||
|
# Specific to the underlying KeyValueStore that backs the crypto key store.
|
||||||
|
#path: "/tmp/hfc-cvs"
|
||||||
|
|
||||||
|
# [Optional]. Specific to Composer environment
|
||||||
|
#wallet: wallet-name
|
||||||
|
|
||||||
|
#
|
||||||
|
# [Optional]. But most apps would have this section so that channel objects can be constructed
|
||||||
|
# based on the content below. If an app is creating channels, then it likely will not need this
|
||||||
|
# section.
|
||||||
|
#
|
||||||
|
channels:
|
||||||
|
# name of the channel
|
||||||
|
papernet:
|
||||||
|
# Required. list of orderers designated by the application to use for transactions on this
|
||||||
|
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
|
||||||
|
# operational decisions to share loads from applications among the orderers. The values must
|
||||||
|
# be "names" of orgs defined under "organizations/peers"
|
||||||
|
orderers:
|
||||||
|
- orderer.magnetocorp.com
|
||||||
|
|
||||||
|
# Required. list of peers from participating orgs
|
||||||
|
peers:
|
||||||
|
peer1.magnetocorp.com:
|
||||||
|
# [Optional]. will this peer be sent transaction proposals for endorsement? The peer must
|
||||||
|
# have the chaincode installed. The app can also use this property to decide which peers
|
||||||
|
# to send the chaincode install request. Default: true
|
||||||
|
endorsingPeer: true
|
||||||
|
|
||||||
|
# [Optional]. will this peer be sent query proposals? The peer must have the chaincode
|
||||||
|
# installed. The app can also use this property to decide which peers to send the
|
||||||
|
# chaincode install request. Default: true
|
||||||
|
chaincodeQuery: true
|
||||||
|
|
||||||
|
# [Optional]. will this peer be sent query proposals that do not require chaincodes, like
|
||||||
|
# queryBlock(), queryTransaction(), etc. Default: true
|
||||||
|
ledgerQuery: true
|
||||||
|
|
||||||
|
# [Optional]. will this peer be the target of the SDK's listener registration? All peers can
|
||||||
|
# produce events but the app typically only needs to connect to one to listen to events.
|
||||||
|
# Default: true
|
||||||
|
eventSource: true
|
||||||
|
|
||||||
|
peer2.digibank.com:
|
||||||
|
endorsingPeer: true
|
||||||
|
chaincodeQuery: false
|
||||||
|
ledgerQuery: true
|
||||||
|
eventSource: true
|
||||||
|
|
||||||
|
# [Optional]. what chaincodes are expected to exist on this channel? The application can use
|
||||||
|
# this information to validate that the target peers are in the expected state by comparing
|
||||||
|
# this list with the query results of getInstalledChaincodes() and getInstantiatedChaincodes()
|
||||||
|
chaincodes:
|
||||||
|
# the format follows the "cannonical name" of chaincodes by fabric code
|
||||||
|
- example02:v1
|
||||||
|
- marbles:1.0
|
||||||
|
|
||||||
|
#
|
||||||
|
# list of participating organizations in this network
|
||||||
|
#
|
||||||
|
organizations:
|
||||||
|
Org1:
|
||||||
|
mspid: magnetocorpMSP
|
||||||
|
|
||||||
|
peers:
|
||||||
|
- peer1.magnetocorp.com
|
||||||
|
|
||||||
|
# [Optional]. Certificate Authorities issue certificates for identification purposes in a Fabric based
|
||||||
|
# network. Typically certificates provisioning is done in a separate process outside of the
|
||||||
|
# runtime network. Fabric-CA is a special certificate authority that provides a REST APIs for
|
||||||
|
# dynamic certificate management (enroll, revoke, re-enroll). The following section is only for
|
||||||
|
# Fabric-CA servers.
|
||||||
|
certificateAuthorities:
|
||||||
|
- ca-magnetocorp
|
||||||
|
|
||||||
|
# [Optional]. If the application is going to make requests that are reserved to organization
|
||||||
|
# administrators, including creating/updating channels, installing/instantiating chaincodes, it
|
||||||
|
# must have access to the admin identity represented by the private key and signing certificate.
|
||||||
|
# Both properties can be the PEM string or local path to the PEM file. Note that this is mainly for
|
||||||
|
# convenience in development mode, production systems should not expose sensitive information
|
||||||
|
# this way. The SDK should allow applications to set the org admin identity via APIs, and only use
|
||||||
|
# this route as an alternative when it exists.
|
||||||
|
adminPrivateKey:
|
||||||
|
path: commercial-paper/organization/magnetocorp/users/Admin@magnetocorp/keystore/9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk
|
||||||
|
signedCert:
|
||||||
|
path: comercial-paper/organization/magnetocorp/users/Admin@magnetocorp.com/signcerts/Admin@magnetocorp.com-cert.pem
|
||||||
|
|
||||||
|
# the profile will contain public information about organizations other than the one it belongs to.
|
||||||
|
# These are necessary information to make transaction lifecycles work, including MSP IDs and
|
||||||
|
# peers with a public URL to send transaction proposals. The file will not contain private
|
||||||
|
# information reserved for members of the organization, such as admin key and certificate,
|
||||||
|
# fabric-ca registrar enroll ID and secret, etc.
|
||||||
|
Org2:
|
||||||
|
mspid: digibankMSP
|
||||||
|
peers:
|
||||||
|
- peer1.digibank.com
|
||||||
|
certificateAuthorities:
|
||||||
|
- ca-digibank
|
||||||
|
adminPrivateKey:
|
||||||
|
path: commercial-paper/organization/digibank/users/Admin@digibank.com/keystore/5a983ddcbefe52a7f9b8ee5b85a590c3e3a43c4ccd70c7795bec504e7f74848d_sk
|
||||||
|
signedCert:
|
||||||
|
path: commercial-paper/organization/digibank/users/Admin@digibank.com/signcerts/Admin@digibank.com-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# List of orderers to send transaction and channel create/update requests to. For the time
|
||||||
|
# being only one orderer is needed. If more than one is defined, which one get used by the
|
||||||
|
# SDK is implementation specific. Consult each SDK's documentation for its handling of orderers.
|
||||||
|
#
|
||||||
|
orderers:
|
||||||
|
orderer.magnetocorp.com:
|
||||||
|
url: grpcs://localhost:7050
|
||||||
|
|
||||||
|
# these are standard properties defined by the gRPC library
|
||||||
|
# they will be passed in as-is to gRPC client constructor
|
||||||
|
grpcOptions:
|
||||||
|
ssl-target-name-override: orderer.example.com
|
||||||
|
|
||||||
|
tlsCACerts:
|
||||||
|
path: comercial-paper/organization/magnetocorp/orderer/orderer.magnetocorp.com/tlscacerts/example.com-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# List of peers to send various requests to, including endorsement, query
|
||||||
|
# and event listener registration.
|
||||||
|
#
|
||||||
|
peers:
|
||||||
|
peer1.magnetocorp.com:
|
||||||
|
# this URL is used to send endorsement and query requests
|
||||||
|
url: grpcs://localhost:7051
|
||||||
|
|
||||||
|
grpcOptions:
|
||||||
|
ssl-target-name-override: peer1.magnetocorp.com
|
||||||
|
request-timeout: 120
|
||||||
|
|
||||||
|
tlsCACerts:
|
||||||
|
path: certificates/magnetocorp/magnetocorp.com-cert.pem
|
||||||
|
|
||||||
|
peer1.digibank.com:
|
||||||
|
url: grpcs://localhost:8051
|
||||||
|
grpcOptions:
|
||||||
|
ssl-target-name-override: peer1.digibank.com
|
||||||
|
tlsCACerts:
|
||||||
|
path: certificates/digibank/digibank.com-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fabric-CA is a special kind of Certificate Authority provided by Hyperledger Fabric which allows
|
||||||
|
# certificate management to be done via REST APIs. Application may choose to use a standard
|
||||||
|
# Certificate Authority instead of Fabric-CA, in which case this section would not be specified.
|
||||||
|
#
|
||||||
|
certificateAuthorities:
|
||||||
|
ca-org1:
|
||||||
|
url: https://localhost:7054
|
||||||
|
# the properties specified under this object are passed to the 'http' client verbatim when
|
||||||
|
# making the request to the Fabric-CA server
|
||||||
|
httpOptions:
|
||||||
|
verify: false
|
||||||
|
tlsCACerts:
|
||||||
|
path: commercial-paper/organization/magnetocorp/ca/magnetocorp.com-cert.pem
|
||||||
|
|
||||||
|
# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
|
||||||
|
# needed to enroll and invoke new users.
|
||||||
|
registrar:
|
||||||
|
- enrollId: admin
|
||||||
|
enrollSecret: adminpw
|
||||||
|
# [Optional] The optional name of the CA.
|
||||||
|
caName: ca-magnetocorp
|
||||||
|
|
||||||
|
ca-org2:
|
||||||
|
url: https://localhost:8054
|
||||||
|
httpOptions:
|
||||||
|
verify: false
|
||||||
|
tlsCACerts:
|
||||||
|
path: commercial-paper/organization/digibank/ca/digibank.com-cert.pem
|
||||||
|
registrar:
|
||||||
|
- enrollId: admin
|
||||||
|
enrollSecret: adminpw
|
||||||
|
# [Optional] The optional name of the CA.
|
||||||
|
caName: ca-digibank
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
mocha: true
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 8,
|
||||||
|
sourceType: 'script'
|
||||||
|
},
|
||||||
|
extends: "eslint:recommended",
|
||||||
|
rules: {
|
||||||
|
indent: ['error', 4],
|
||||||
|
'linebreak-style': ['error', 'unix'],
|
||||||
|
quotes: ['error', 'single'],
|
||||||
|
semi: ['error', 'always'],
|
||||||
|
'no-unused-vars': ['error', { args: 'none' }],
|
||||||
|
'no-console': 'off',
|
||||||
|
curly: 'error',
|
||||||
|
eqeqeq: 'error',
|
||||||
|
'no-throw-literal': 'error',
|
||||||
|
strict: 'error',
|
||||||
|
'no-var': 'error',
|
||||||
|
'dot-notation': 'error',
|
||||||
|
'no-tabs': 'error',
|
||||||
|
'no-trailing-spaces': 'error',
|
||||||
|
'no-use-before-define': 'error',
|
||||||
|
'no-useless-call': 'error',
|
||||||
|
'no-with': 'error',
|
||||||
|
'operator-linebreak': 'error',
|
||||||
|
yoda: 'error',
|
||||||
|
'quote-props': ['error', 'as-needed']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Bring key classes into scope, most importantly Fabric SDK network class
|
||||||
|
const fs = require('fs');
|
||||||
|
const { FileSystemWallet, X509WalletMixin } = require('fabric-network');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const fixtures = path.resolve(__dirname, '../../../../basic-network');
|
||||||
|
|
||||||
|
// A wallet stores a collection of identities
|
||||||
|
const wallet = new FileSystemWallet('../identity/user/isabella/wallet');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
|
||||||
|
// Main try/catch block
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Identity to credentials to be stored in the wallet
|
||||||
|
const credPath = path.join(fixtures, '/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com');
|
||||||
|
const cert = fs.readFileSync(path.join(credPath, '/msp/signcerts/User1@org1.example.com-cert.pem')).toString();
|
||||||
|
const key = fs.readFileSync(path.join(credPath, '/msp/keystore/c75bd6911aca808941c3557ee7c97e90f3952e379497dc55eb903f31b50abc83_sk')).toString();
|
||||||
|
|
||||||
|
// Load credentials into wallet
|
||||||
|
const identityLabel = 'User1@org1.example.com';
|
||||||
|
const identity = X509WalletMixin.createIdentity('Org1MSP', cert, key);
|
||||||
|
|
||||||
|
await wallet.import(identityLabel, identity);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Error adding to wallet. ${error}`);
|
||||||
|
console.log(error.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(() => {
|
||||||
|
console.log('done');
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log(e);
|
||||||
|
console.log(e.stack);
|
||||||
|
process.exit(-1);
|
||||||
|
});
|
||||||
102
commercial-paper/organization/magnetocorp/application/issue.js
Normal file
102
commercial-paper/organization/magnetocorp/application/issue.js
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This application has 6 basic steps:
|
||||||
|
* 1. Select an identity from a wallet
|
||||||
|
* 2. Connect to network gateway
|
||||||
|
* 3. Access PaperNet network
|
||||||
|
* 4. Construct request to issue commercial paper
|
||||||
|
* 5. Submit transaction
|
||||||
|
* 6. Process response
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Bring key classes into scope, most importantly Fabric SDK network class
|
||||||
|
const fs = require('fs');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
const { FileSystemWallet, Gateway } = require('fabric-network');
|
||||||
|
const CommercialPaper = require('../contract/lib/paper.js');
|
||||||
|
|
||||||
|
// A wallet stores a collection of identities for use
|
||||||
|
//const wallet = new FileSystemWallet('../user/isabella/wallet');
|
||||||
|
const wallet = new FileSystemWallet('../identity/user/isabella/wallet');
|
||||||
|
|
||||||
|
// Main program function
|
||||||
|
async function main() {
|
||||||
|
|
||||||
|
// A gateway defines the peers used to access Fabric networks
|
||||||
|
const gateway = new Gateway();
|
||||||
|
|
||||||
|
// Main try/catch block
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Specify userName for network access
|
||||||
|
// const userName = 'isabella.issuer@magnetocorp.com';
|
||||||
|
const userName = 'User1@org1.example.com';
|
||||||
|
|
||||||
|
// Load connection profile; will be used to locate a gateway
|
||||||
|
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8'));
|
||||||
|
|
||||||
|
// Set connection options; identity and wallet
|
||||||
|
let connectionOptions = {
|
||||||
|
identity: userName,
|
||||||
|
wallet: wallet,
|
||||||
|
discovery: { enabled:false, asLocalhost: true }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Connect to gateway using application specified parameters
|
||||||
|
console.log('Connect to Fabric gateway.');
|
||||||
|
|
||||||
|
await gateway.connect(connectionProfile, connectionOptions);
|
||||||
|
|
||||||
|
// Access PaperNet network
|
||||||
|
console.log('Use network channel: mychannel.');
|
||||||
|
|
||||||
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
||||||
|
// Get addressability to commercial paper contract
|
||||||
|
console.log('Use org.papernet.commercialpaper smart contract.');
|
||||||
|
|
||||||
|
const contract = await network.getContract('papercontract', 'org.papernet.commercialpaper');
|
||||||
|
|
||||||
|
// issue commercial paper
|
||||||
|
console.log('Submit commercial paper issue transaction.');
|
||||||
|
|
||||||
|
const issueResponse = await contract.submitTransaction('issue', 'MagnetoCorp', '00001', '2020-05-31', '2020-11-30', '5000000');
|
||||||
|
|
||||||
|
// process response
|
||||||
|
console.log('Process issue transaction response.');
|
||||||
|
|
||||||
|
let paper = CommercialPaper.fromBuffer(issueResponse);
|
||||||
|
|
||||||
|
console.log(`${paper.issuer} commercial paper : ${paper.paperNumber} successfully issued for value ${paper.faceValue}`);
|
||||||
|
console.log('Transaction complete.');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
console.log(`Error processing transaction. ${error}`);
|
||||||
|
console.log(error.stack);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
// Disconnect from the gateway
|
||||||
|
console.log('Disconnect from Fabric gateway.')
|
||||||
|
gateway.disconnect();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main().then(() => {
|
||||||
|
|
||||||
|
console.log('Issue program complete.');
|
||||||
|
|
||||||
|
}).catch((e) => {
|
||||||
|
|
||||||
|
console.log('Issue program exception.');
|
||||||
|
console.log(e);
|
||||||
|
console.log(e.stack);
|
||||||
|
process.exit(-1);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "nodejs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "issue.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "rm -rf _idwallet && node addToWallet.js && node issue.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"fabric-network": "^1.4.0-beta",
|
||||||
|
"fabric-client": "^1.4.0-beta",
|
||||||
|
"js-yaml": "^3.12.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^5.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
#
|
||||||
|
# Copyright IBM Corp All Rights Reserved
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
networks:
|
||||||
|
basic:
|
||||||
|
external:
|
||||||
|
name: net_basic
|
||||||
|
|
||||||
|
services:
|
||||||
|
cliMagnetoCorp:
|
||||||
|
container_name: cliMagnetoCorp
|
||||||
|
image: hyperledger/fabric-tools
|
||||||
|
tty: true
|
||||||
|
environment:
|
||||||
|
- GOPATH=/opt/gopath
|
||||||
|
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
|
||||||
|
- CORE_LOGGING_LEVEL=info
|
||||||
|
- CORE_PEER_ID=cli
|
||||||
|
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||||
|
- CORE_PEER_LOCALMSPID=Org1MSP
|
||||||
|
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||||
|
- CORE_CHAINCODE_KEEPALIVE=10
|
||||||
|
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
|
||||||
|
command: /bin/bash
|
||||||
|
volumes:
|
||||||
|
- /var/run/:/host/var/run/
|
||||||
|
- ./../../../../organization/magnetocorp:/opt/gopath/src/github.com/
|
||||||
|
- ./../../../../../basic-network/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
|
||||||
|
networks:
|
||||||
|
- basic
|
||||||
|
#depends_on:
|
||||||
|
# - orderer.example.com
|
||||||
|
# - peer0.org1.example.com
|
||||||
|
# - couchdb
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue