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

Conversation

oxarbitrage
Copy link
Member

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 oxarbitrage changed the title Create template script Create plugin script Sep 2, 2018
@clockworkgr
Copy link
Member

Nice!

@pmconrad
Copy link
Contributor

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.

@oxarbitrage
Copy link
Member Author

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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {} \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

exit 1
fi

pluginName=$1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put double quotes around all strings where variables are expanded.


echo Copying template...
echo "Copying template..."
cp -r template_plugin $pluginName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {} \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {} \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please quote $pluginName

@pmconrad
Copy link
Contributor

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
@oxarbitrage
Copy link
Member Author

thanks @pmconrad :)

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

Successfully merging this pull request may close these issues.

5 participants