- Deployed Waves Enterprise Node (version 1.4.0 has been tested).
SENDER=
KEYPAIR_PASSWORD=
NODE_URL=http://localhost:6862
import json
import os
import requests
import sys
def find_param_value(params, name):
for param in params:
if param['key'] == name: return param['value']
return None
def print_success(results):
print(json.dumps(results, separators=(',', ':')))
def print_error(message):
print(message)
sys.exit(3)
def get_value(contract_id):
node = os.environ['NODE_API']
if not node:
print_error("Node REST API address is not defined")
token = os.environ["API_TOKEN"]
if not token:
print_error("Node API token is not defined")
headers = {'X-Contract-Api-Token': token}
url = '{0}/internal/contracts/{1}/sum'.format(node, contract_id)
r = requests.get(url, verify=False, timeout=2, headers=headers)
data = r.json()
return data['value']
if __name__ == '__main__':
command = os.environ['COMMAND']
if command == 'CALL':
contract_id = json.loads(os.environ['TX'])['contractId']
value = get_value(contract_id)
print_success([{
"key": "sum",
"type": "integer",
"value": value + 1}])
elif command == 'CREATE':
print_success([{
"key": "sum",
"type": "integer",
"value": 0}])
else:
print_error("Unknown command {0}".format(command))
#!/bin/sh
python contract.py
FROM python:alpine3.8
RUN pip install requests
ADD contract.py /
ADD run.sh /
RUN chmod +x run.sh
CMD exec /bin/sh -c "trap : TERM INT; (while true; do sleep 1000; done) & wait"
docker build -t test-contract src
docker image tag test-contract registry:5000/test-contract
docker push registry:5000/test-contract
IMAGE_ID=`docker inspect registry:5000/test-contract | grep Id | cut -d'"' -f 4 | cut -d":" -f 2`
echo $IMAGE_ID
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-Contract-Api-Token' -d " { \
\"fee\": 100000000, \
\"image\": \"test-contract:latest\", \
\"imageHash\": \"$IMAGE_ID\", \
\"contractName\": \"test-contract\", \
\"sender\": \"$SENDER\", \
\"password\": \"$KEYPAIR_PASSWORD\", \
\"params\": [], \
\"type\": 103, \
\"version\": 1 \
}" "$NODE_URL/transactions/signAndBroadcast"
Id field from JSON result.
TXID=
curl $NODE_URL/transactions/info/$TXID
CONTRACT_ID=$TXID
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-Contract-Api-Token' -d "{ \
\"contractId\": \"$CONTRACT_ID\", \
\"fee\": 10, \
\"sender\": \"$SENDER\", \
\"password\": \"$KEYPAIR_PASSWORD\", \
\"type\": 104, \
\"version\": 1, \
\"params\": [ \
{ \
\"type\": \"integer\", \
\"key\": \"a\", \
\"value\": 4 \
} \
] \
}" "$NODE_URL/transactions/signAndbroadcast"
curl $NODE_URL/contracts/$CONTRACT_ID