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

Support invoke command #390

Open
dzikowski opened this issue Jun 20, 2023 · 1 comment
Open

Support invoke command #390

dzikowski opened this issue Jun 20, 2023 · 1 comment

Comments

@dzikowski
Copy link
Contributor

dzikowski commented Jun 20, 2023

Right now we have a buch of test scripts to verify if invoking chaincodes work (e2e-network/expect-invoke-cli.sh and similar). For the simplest Docker setup it is handled by executing some operations on the CLI container:

peerAddresses="--peerAddresses $(echo "$peer" | sed 's/,/ --peerAddresses /g')"

response="$(
  # shellcheck disable=SC2086
  docker exec "$cli" peer chaincode invoke \
    $peerAddresses \
    -C "$channel" \
    -n "$chaincode" \
    -c "$command" \
    --transient "$transient" \
    --waitForEvent \
    --waitForEventTimeout 90s \
    2>&1
)"

We want invoke command to be supported by Fablo, with the syntax similar to our channel query scripts. Within this issue we want to support invoke command for the simplest use case: no TLS, Docker setup, and using CLI container. Relevant script is expect-invoke-cli.sh. After this issue, the script, instead of invoking docker, should call (some path)/fablo.sh chaincode invoke (some params).

Probably the best way to implement this is to follow the similar approach as for channel query scripts - using templates and strong validation.

Desired syntax:

fablo chaincode invoke <channel_name> <chaincode_name> <peers_dmains_comma_separated>  <command> <transient>

Sample:

fablo chaincode invoke my-channel1 chaincode1 'peer0.org1.example.com,peer0.org2.example.com' '{"Args":["KVContract:put", "name", "James Bond"]}'

No need for additional tests. In order to verify the code works we just want to replace the content of expect-invoke-cli.sh script.

This issue, however includes upgrade of README.

Further steps:

  1. Support chaincode query
  2. Suport invoke with TLS
  3. Support invoke for kubernetes
@dzikowski
Copy link
Contributor Author

dzikowski commented Sep 8, 2023

The second step for this command after #403 is to ensure we have consistent API - the same as for chaincode list #406 and we use generators to make it work with custom network topologies.

Checklist for the second step:

  • chaincodeInvoke in chaincode-scripts.sh should use generators as in the listing below
  • peerChaincodeInvoke should be added to chaincode-functions-v2.sh
  • chaincodeInvoke in chaincode-scripts.sh should use peerChaincodeInvoke to invoke chaincodes
  • peerChaincodeInvoke should be able to call multiple peers (it should include the part: PEER_ADDRESSES="--peerAddresses $(echo "$PEERS" | sed 's/,/ --peerAddresses /g')") => to be resolved in separate issue
  • peerChaincodeInvokeTls should be added to chaincode-functions-v2.sh
  • expect-invoke-cli-tls.sh file should be removed. test-02-raft-2orgs.sh should use expect-invoke-cli.sh instead

Suggested implementation for chaincodeInvoke() in chaincode-scripts.sh:

# Function to perform chaincode invoke. Accepts 5 parameters:
#   1. comma-separated peers
#   2. channel name
#   3. chaincode name
#   4. chaincode command
#   5. transient data (optional)
chaincodeInvoke() {
  if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
    echo "Expected 4 or 5 parameters for chaincode list, but got: $*"
    echo "Usage: fablo chaincode invoke <peer_domains_comma_separated> <channel_name> <chaincode_name> <command> [transient]"
    exit 1
  fi
  cli=""
  peer_addresses=""
  <% if (!global.tls) { %>
    peer_certs=""
  <% } %>
  <% orgs.forEach((org) => { -%>
    <% org.peers.forEach((peer) => { -%>
      if [[ "$1" == *"<%= peer.address %>"* ]]; then
        cli="<%= org.cli.address %>"
        peer_addresses="$peer_addresses,<%= peer.fullAddress %>"
        <% if(!global.tls) { %>
          peer_certs="$peer_certs,crypto/peers/<%= peer.address %>/tls/ca.crt"
        <% } %>
      fi
    <% }) -%>
  <% }) -%>
  if [ -z "$peer_addresses" ]; then
    echo "Unknown peers: $1"
    exit 1
  fi
  <% if(!global.tls) { %>
    peerChaincodeInvoke "$cli" "${peer_addresses:1}" "$2" "$3" "$4" "$5"
  <% } else { %>
    peerChaincodeInvokeTls "$cli" "${peer_addresses:1}" "$2" "$3" "$4" "$5" "${peer_certs:1}"
  <% } %>
}

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