mesg-foundation / engine

Build apps or autonomous workflows with reusable, shareable integrations connecting any service, app, blockchain or decentralized network.
https://mesg.com/
Apache License 2.0
130 stars 13 forks source link

Add tx commands for service, process, execution and runner modules #1798

Closed NicolasMahe closed 4 years ago

NicolasMahe commented 4 years ago

Add write commands for all modules

The commands service create, process create, execution create and execution update require the data to be passed as JSON because of the complexity of the data. It makes them hard to use as the JSON is also complicated to write. @antho1404 do you have a suggestion to improve this issue? Should I make a simple version based on flags but that can only fill the root keys?

Example of use:

go run ./cmd/mesg-cli tx service create  --from engine2 --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto '{"sid":"emit-event-interval","name":"Service Emit Event Interval","description":"Emits events on regular intervals","repository":"https://github.com/liteflow-services/emit-event-interval","configuration":{},"dependencies":[],"tasks":[],"events":[{"key":"every_1_second","name":"Every 1 second","description":"Emits an event every 1 second","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_2_seconds","name":"Every 2 seconds","description":"Emits an event every 2 seconds","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_5_seconds","name":"Every 5 seconds","description":"Emits an event every 5 seconds","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_10_seconds","name":"Every 10 seconds","description":"Emits an event every 10 seconds","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_30_seconds","name":"Every 30 seconds","description":"Emits an event every 30 seconds","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_1_minute","name":"Every 1 minute","description":"Emits an event every 1 minute","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_2_minutes","name":"Every 2 minutes","description":"Emits an event every 2 minutes","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_5_minutes","name":"Every 5 minutes","description":"Emits an event every 5 minutes","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_10_minutes","name":"Every 10 minutes","description":"Emits an event every 10 minutes","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_30_minutes","name":"Every 30 minutes","description":"Emits an event every 30 minutes","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_1_hour","name":"Every 1 hour","description":"Emits an event every 1 hour","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_2_hours","name":"Every 2 hours","description":"Emits an event every 2 hours","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_6_hours","name":"Every 6 hours","description":"Emits an event every 6 hours","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_12_hours","name":"Every 12 hours","description":"Emits an event every 12 hours","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]},{"key":"every_24_hours","name":"Every 24 hours","description":"Emits an event every 24 hours","data":[{"key":"timestamp","name":"Timestamp (ms)","description":"The timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC","type":"Number","object":[]}]}],"source":"QmPNUbFGZa5hvVCf1CAjFLfv5ZTykgpkU6sYXYXAEMzQMH"}'

go run ./cmd/mesg-cli tx runner create SERVICE_HASH --from engine2 --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto
go run ./cmd/mesg-cli tx runner delete RUNNER_HASH --from engine2 --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto

# TODO: add the args
go run ./cmd/mesg-cli tx process create --from engine --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto '{"name":"webhook","nodes":[{"key":"node-0","Type":{"type":"mesg.types.Process_Node_Event_","value":{"event":{"instanceHash":"8dD91Yx9N7kywn8MtQ9PxReWpdjpeGgSMvZsgWcnG27y","eventKey":"every_10_seconds"}}}},{"key":"node-1-inputs","Type":{"type":"mesg.types.Process_Node_Map_","value":{"map":[{"Key":"data","Value":{"Value":{"type":"mesg.types.Process_Node_Map_Output_Map_","value":{"map":[{"Key":"foo","Value":{"Value":{"type":"mesg.types.Process_Node_Map_Output_StringConst","value":{"string_const":"bar"}}}}]}}}},{"Key":"url","Value":{"Value":{"type":"mesg.types.Process_Node_Map_Output_StringConst","value":{"string_const":"https://webhook.site/ad536a28-4b19-4562-a756-f20027e25c5a"}}}}]}}},{"key":"node-1","Type":{"type":"mesg.types.Process_Node_Task_","value":{"task":{"instanceHash":"HVso8L6QtToBNomhDvnfobygr6YAtmXRAqdkJsw9s36e","taskKey":"call"}}}}],"edges":[{"src":"node-0","dst":"node-1-inputs"},{"src":"node-1-inputs","dst":"node-1"}]}'

go run ./cmd/mesg-cli tx process delete --from ACCOUNT --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto 9hFpz4Mq5KBfwVzKSoCEr3hFC1DFicEkMx13Uyr7oKWj

go run ./cmd/mesg-cli tx execution create --from engine --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto --yes '{"taskKey":"call","eventHash":"9hFpz4Mq5KBfwVzKSoCEr3hFC1DFicEkMx13Uyr7oKWj","executorHash":"8xdAhmoXcYtMobe6xwjMboDGPhqE7iMjY1iJ2WjbLwVS","price":"10000atto"}'

go run ./cmd/mesg-cli tx execution update --from engine --chain-id "mesg-dev-chain" -b block --gas-prices=1.0atto --yes '{"hash":"9hFpz4Mq5KBfwVzKSoCEr3hFC1DFicEkMx13Uyr7oKWj","executor":"mesgXXX","result":""}'
antho1404 commented 4 years ago

I would definitely not go with flags as it will be really complex/impossible for services/processes. Instead, just the JSON in argument or as a file will be more than enough. I would also normalize that and have this for the runner as well even if it can be simplified but instead of

go run ./cmd/mesg-cli tx runner create BFBCRiRqD8VEU1qPC47WMXPYK5qGJCw6cbX3H2cekdU7 --from engine -b block

I would have

go run ./cmd/mesg-cli tx runner create '{"serviceHash": "BFBCRiRqD8VEU1qPC47WMXPYK5qGJCw6cbX3H2cekdU7"}' --from engine -b block
NicolasMahe commented 4 years ago

I would definitely not go with flags as it will be really complex/impossible for services/processes. Instead, just the JSON in argument or as a file will be more than enough. I would also normalize that and have this for the runner as well even if it can be simplified but instead of

go run ./cmd/mesg-cli tx runner create BFBCRiRqD8VEU1qPC47WMXPYK5qGJCw6cbX3H2cekdU7 --from engine -b block

I would have

go run ./cmd/mesg-cli tx runner create '{"serviceHash": "BFBCRiRqD8VEU1qPC47WMXPYK5qGJCw6cbX3H2cekdU7"}' --from engine -b block

Only the command runner create, delete and process delete are not using the JSON definition. The reason is all other cosmos commands are using args and flags, I don't want to do something different except if I don't have a choice.