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

Create plugin script #1302

Merged
merged 7 commits into from Sep 28, 2018
Merged

Create plugin script #1302

merged 7 commits into from Sep 28, 2018

Conversation

@oxarbitrage
Copy link
Member

@oxarbitrage oxarbitrage commented Sep 2, 2018

When working with plugins the developer find himself doing the same renaming work too many times.

I found a script in eos that actually do the job of automating plugin creation: https://github.com/EOSIO/eos/blob/master/plugins/eosio-make_new_plugin.sh

So i copied over and added some further instructions to get up and running in bitshares after the files are all in place.

The template is a plugin with implementation class, most of our plugins are like that even if there are others that don't follow this pattern i think this is the way most of them can be built.

It haves some minimal functionality on how to add an argument and an onBlock function that will execute every block.

For further examples the developer will check other plugins, unfortunately we have no plugin that exposes api calls in the plugin itself. This is only visible on @xeroc hello plugin:

https://github.com/bitshares/bitshares-core/tree/hello_plugin/libraries/plugins

I think we should encourage the use of the api in the plugin itself rather than adding to api.cpp but i didn't added this to template as most plugins will not want it, tried to keep it simple.

Sample script output:

alfredo@alfredo-Inspiron-5559 ~/CLionProjects/template_plugin/libraries/plugins $ ./make_new_plugin.sh stoploss
Copying template...
Renaming files/directories...
Renaming in files...
Done! stoploss is ready.
Next steps:
1- Add 'add_subdirectory( stoploss )' to CmakeLists.txt in this directory.
2- Add 'graphene_stoploss' to ../../programs/witness_node/CMakeLists.txt with the other plugins.
3- Include plugin header file '#include <graphene/stoploss/stoploss.hpp>' to ../../programs/witness_node/main.cpp.
4- Initialize plugin with the others with 'auto stoploss_plug = node->register_plugin<stoploss::stoploss>();' in ../../programs/witness_node/main.cpp
5- cmake and make
5- Start plugin with './../programs/witness_node/witness_node --plugins "stoploss"'. After the seed nodes are added you start to see see a msgs from the plugin 'onBlock' 
alfredo@alfredo-Inspiron-5559 ~/CLionProjects/template_plugin/libraries/plugins $ 
oxarbitrage added 2 commits Sep 2, 2018
@oxarbitrage oxarbitrage changed the title Create template script Create plugin script Sep 2, 2018
@clockworkgr
Copy link
Member

@clockworkgr clockworkgr commented Sep 3, 2018

Nice!

@ryanRfox ryanRfox added this to In progress in Feature release (201810) via automation Sep 3, 2018
@pmconrad
Copy link
Contributor

@pmconrad pmconrad commented Sep 5, 2018

It would be nice to have the script look up used database space ID from other plugins and automatically select a new one.

@abitmore abitmore removed this from In progress in Feature release (201810) Sep 14, 2018
@abitmore abitmore added this to In progress in Feature Release (201902) via automation Sep 14, 2018
@oxarbitrage
Copy link
Member Author

@oxarbitrage oxarbitrage commented Sep 27, 2018

I am not very good at bash but created a function in script to detect biggest space_id and sum 1 to it. This number will be used in the template being created. This is at 64505a8

for i in * ; do
if [ -d "$i" ] && [ "$i" != "CMakeFiles" ]; then
cd "$i/include/graphene/$i"
result=$(grep -rnw '.' -e '#define [[:alnum:]]*_SPACE_ID')

This comment has been minimized.

@pmconrad

pmconrad Sep 27, 2018
Contributor

Should use [[:space]]* after #define instead of single space

@@ -16,6 +36,10 @@ mv $pluginName/include/graphene/template_plugin $pluginName/include/graphene/$pl
for file in `find $pluginName -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/$pluginName/g <<< $file`; done;
echo Renaming in files...
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \;
echo Assigning next available SPACE_ID...
next_space_id
find $pluginName -type f -exec sed -i "s/0000/$?/g" {} \;

This comment has been minimized.

@pmconrad

pmconrad Sep 27, 2018
Contributor

Better use something that's recognizable as a placeholder, like @SPACE_ID@, not a valid integer number.

exit 1
fi

pluginName=$1

This comment has been minimized.

@pmconrad

pmconrad Sep 27, 2018
Contributor

Put double quotes around all strings where variables are expanded.


echo Copying template...
echo "Copying template..."
cp -r template_plugin $pluginName

This comment has been minimized.

@pmconrad

pmconrad Sep 27, 2018
Contributor

Please quote $pluginName here and in the following lines.


echo "Renaming files/directories..."
mv "$pluginName/include/graphene/template_plugin" "$pluginName/include/graphene/$pluginName"
for file in `find "$pluginName" -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/"$pluginName"/g <<< $file`; done;

This comment has been minimized.

@pmconrad

pmconrad Sep 28, 2018
Contributor

Please quote $file

mv "$pluginName/include/graphene/template_plugin" "$pluginName/include/graphene/$pluginName"
for file in `find "$pluginName" -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/"$pluginName"/g <<< $file`; done;
echo "Renaming in files..."
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \;

This comment has been minimized.

@pmconrad

pmconrad Sep 28, 2018
Contributor

Please quote $pluginName

find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \;
echo "Assigning next available SPACE_ID..."
next_space_id
find $pluginName -type f -exec sed -i "s/@SPACE_ID@/$?/g" {} \;

This comment has been minimized.

@pmconrad

pmconrad Sep 28, 2018
Contributor

Please quote $pluginName

Feature Release (201902) automation moved this from In progress to Reviewer approved Sep 28, 2018
@pmconrad
Copy link
Contributor

@pmconrad pmconrad commented Sep 28, 2018

Excellent, tested successfully. Some of the "next steps" could also be automated, but I think it might be better to leave these as manual steps.
Thanks!

@oxarbitrage oxarbitrage merged commit 90ae25d into bitshares:develop Sep 28, 2018
2 checks passed
2 checks passed
ci/dockercloud Your tests passed in Docker Cloud
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Feature Release (201902) automation moved this from Reviewer approved to Done Sep 28, 2018
@oxarbitrage
Copy link
Member Author

@oxarbitrage oxarbitrage commented Sep 28, 2018

thanks @pmconrad :)

@abitmore abitmore removed this from Done in Feature Release (201902) Sep 28, 2018
@abitmore abitmore added this to In progress in Feature release (201810) via automation Sep 28, 2018
@abitmore abitmore moved this from In progress to Done in Feature release (201810) Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.