Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chainnodeを動かす #6

Open
shohu opened this issue Jun 6, 2019 · 3 comments
Open

chainnodeを動かす #6

shohu opened this issue Jun 6, 2019 · 3 comments

Comments

@shohu
Copy link
Owner

shohu commented Jun 6, 2019

chainnodeの雛形ができたので、実際にestateを登録するところまでやってみる

@shohu
Copy link
Owner Author

shohu commented Jun 6, 2019

環境構築

reset

$ docker stop $(docker ps -q)
$ docker rm $(docker ps -aq)
$ CONTRACT_IMAGE=$(docker images \| grep 'dev-peer0.org1.example.com-papercontract' \| awk '{print $3}')
$ docker rmi $CONTRACT_IMAGE

base network

$ cd basic-network/
$ ./start.sh

monitor起動

以下はずっと起動しっぱなしになる。

$ cd ../estate/configuration/cli/
$ ./monitordocker.sh net_basic

fabric-toolsの起動

hyperledgerとコミュニケーション取るためのもの

$ cd estate/configuration/cli
$ docker-compose -f docker-compose.yml up -d cliMagnetoCorp
Creating cliMagnetoCorp ... done

chaincodeのインストール

peer chaincode install を cliMagnetoCorp で実行する

$ docker exec cliMagnetoCorp peer chaincode install -n estatecontract -v 0 -p /opt/gopath/src/github.com/contract -l node
2019-06-06 01:44:32.834 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-06-06 01:44:32.835 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-06-06 01:44:33.278 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >

chaincodeのinstantiate

peer chaincode instantiate を cliMagnetoCorpで実施する。

docker exec cliMagnetoCorp peer chaincode instantiate -n estatecontract -v 0 -l node -c '{"Args":["org.estatenet.estate:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"

createEstate.js 動かす

$ cd estate/application
$ npm install

wallet追加

user1

$ node addToWallet.js
done

user2

$ node addToWallet.js
done

createEstate.js実行

$ node createEstate.js
Connect to Fabric gateway.
Use network channel: mychannel.
Use org.estatenet.estate smart contract.
Submit estate issue transaction.

Process estate transaction response.
undefined estate : SCFoundation successfully created. price 50000000
Transaction complete.
Disconnect from Fabric gateway.
Estate program complete.

成功した 👍

@shohu
Copy link
Owner Author

shohu commented Jun 6, 2019

chaincodeのinstantiate時にcompileエラー

docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
: 
dev-peer0.org1.example.com-estatecontract-0|{ Error: Cannot find module '../../ledger-api/state.js'
dev-peer0.org1.example.com-estatecontract-0|    at Function.Module._resolveFilename (module.js:547:15)
dev-peer0.org1.example.com-estatecontract-0|    at Function.Module._load (module.js:474:25)
dev-peer0.org1.example.com-estatecontract-0|    at Module.require (module.js:596:17)
dev-peer0.org1.example.com-estatecontract-0|    at require (internal/module.js:11:18)
dev-peer0.org1.example.com-estatecontract-0|    at Object.<anonymous> (/usr/local/src/lib/estate.js:8:15)
dev-peer0.org1.example.com-estatecontract-0|    at Module._compile (module.js:652:30)
dev-peer0.org1.example.com-estatecontract-0|    at Object.Module._extensions..js (module.js:663:10)
dev-peer0.org1.example.com-estatecontract-0|    at Module.load (module.js:565:32)
dev-peer0.org1.example.com-estatecontract-0|    at tryModuleLoad (module.js:505:12)
dev-peer0.org1.example.com-estatecontract-0|    at Function.Module._load (module.js:497:3) code: 'MODULE_NOT_FOUND' }

該当の estate.js のソースを以下にかえても、まったく上のエラーと同じ。何かキャッシュが残っている?

const State = require('../ledger-api/aaaa-state.js');

dockerの全削除してみるか、、、うまくいかない
image削除しないとだめかもしれない、、、、

結局、dev-peer0.org1.example.com-estatecontract-0 を消したら大丈夫だった 👍

@shohu shohu closed this as completed Jun 6, 2019
@shohu shohu reopened this Jun 6, 2019
@shohu
Copy link
Owner Author

shohu commented Jun 6, 2019

estateを全て取得するchaincodeが動かない。

    async findByQuery(query) {
        let iterator = await this.ctx.stub.GetQueryResult(query);

        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);
                return allResults;
            }
        }
    }

を実行すると以下エラー。

TypeError: this.ctx.stub.GetQueryResult is not a function, stack=Error: transaction returned with failure: TypeError: this.ctx.stub.GetQueryResult is not a function

GetQueryResultがないと。

とおもったら、getQueryResult になおしたらうまくいった汗
https://www.ibm.com/developerworks/jp/cloud/library/cl-hyperledger-fabric-couchdb-serach/index.html
の記載のtypoだわいな

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant