forked from axiom-team/ssb-g1-tip
first commit
This commit is contained in:
commit
1fe76a70a3
|
@ -0,0 +1,125 @@
|
|||
#!/bin/bash
|
||||
################################################################################
|
||||
# Authors:
|
||||
# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
|
||||
# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519)
|
||||
# [@Boris](@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519)
|
||||
# Version: 1.0
|
||||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||||
###########################################################################################
|
||||
# ADD G1 Layer 10 LOVE to message writer you like !
|
||||
# INSTALL silkaj sbotc
|
||||
# PREVENT DOUBLE PAYEMENT
|
||||
############################################################################################
|
||||
|
||||
fn_exists() {
|
||||
# appended double quote is an ugly trick to make sure we do get a string -- if $1 is not a known command, type does not output anything
|
||||
[ `type -t $1`"" == 'file' ]
|
||||
}
|
||||
|
||||
|
||||
# INSTALL build-essential
|
||||
|
||||
if ! dpkg -s build-essential; then
|
||||
sudo apt install build-essential -y
|
||||
fi
|
||||
|
||||
# INSTALL silkaj
|
||||
if ! fn_exists silkaj; then
|
||||
echo "INSTALL silkaj"
|
||||
sudo apt-get update -y || true
|
||||
sudo apt install python3-pip python3-setuptools python3-wheel -y && pip3 install silkaj --user
|
||||
echo 'PATH=$PATH:.local/bin' >> ~/.bashrc && source ~/.bashrc
|
||||
fi
|
||||
|
||||
# INSTALL sbotc
|
||||
if ! fn_exists sbotc; then
|
||||
sudo apt install libsodium-dev jq -y
|
||||
git clone https://git.scuttlebot.io/%25133ulDgs%2FoC1DXjoK04vDFy6DgVBB%2FZok15YJmuhD5Q%3D.sha256 sbotc
|
||||
cd sbotc
|
||||
make
|
||||
sudo make install
|
||||
fi
|
||||
|
||||
|
||||
###########################################################################################
|
||||
####################### G1 SSB ACCOUNT MANAGER ############################################
|
||||
###########################################################################################
|
||||
|
||||
# Install DUP-Mnemonic
|
||||
|
||||
if ! fn_exists dup-mnemonic; then
|
||||
cd /tmp
|
||||
git clone https://git.duniter.org/tools/dup-mnemonic-rs
|
||||
cd dup-mnemonic-rs
|
||||
cargo build --release
|
||||
sudo cp target/release/dup-mnemonic /usr/local/bin
|
||||
fi
|
||||
|
||||
# CHECK SSB ~/.ssb/secret
|
||||
if [[ ! -f ~/.ssb/secret ]]; then
|
||||
mkdir -p ~/.ssb
|
||||
echo "WELCOME CREATING YOUR G1 SSB ACCOUNT !!!"
|
||||
echo "CHOOSE YOU LOGIN or LEAVE BLANK & HIT ENTER FOR AUTO GENERATION"
|
||||
read salt
|
||||
[[ $salt != "" ]] && echo "PASSWORD?" && read pepper && [[ $pepper == "" ]] && exit
|
||||
|
||||
|
||||
# GENERATE MNEMONIC KEY: 9 MOTS
|
||||
if [[ $salt == "" ]]; then
|
||||
declare -a makeyarray
|
||||
makeyarray=($(dup-mnemonic -l $lang))
|
||||
# LOGIN (=SALT) 6 MOTS
|
||||
salt="${makeyarray[0]} ${makeyarray[1]} ${makeyarray[2]} ${makeyarray[3]} ${makeyarray[4]} ${makeyarray[5]}"
|
||||
# PASS (=PEPPER) 3 MOTS
|
||||
pepper="${makeyarray[6]} ${makeyarray[7]} ${makeyarray[8]}"
|
||||
fi
|
||||
echo "........."
|
||||
echo "CREDENTIAL: $salt / $pepper"
|
||||
|
||||
# CREATE ~/.ssb/secret.dunikey
|
||||
python3 ./key_create_dunikey.py "$salt" "$pepper"
|
||||
mv ./.secret.dunikey ~/.ssb/secret.dunikey
|
||||
|
||||
# CREATE
|
||||
pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
|
||||
priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
|
||||
ssbpub=$(echo $pub | base58 -d | base64)
|
||||
ssbpriv=$(echo $priv | base58 -d | base64)
|
||||
cat > ~/.ssb/secret <<EOF
|
||||
# This secret is related to your G1Wallet - https://cesium.app
|
||||
# silkaj balance $pub
|
||||
# ID (salt): $salt / Pass: $pepper
|
||||
# THIS KEY IS YOURS! REMIND IT AND KEEP IT SAFE AS A REAL WALLET
|
||||
# chmod 400 ~/.zen/secret
|
||||
|
||||
{
|
||||
"curve": "ed25519",
|
||||
"public": "$ssbpub.ed25519",
|
||||
"private": "$ssbpriv.ed25519",
|
||||
"id": "@$ssbpub.ed25519"
|
||||
}
|
||||
|
||||
# WARNING! It's vital that you DO NOT edit OR share your secret name
|
||||
# instead, share your public name
|
||||
# your SSB public name: @$ssbpub.ed25519
|
||||
EOF
|
||||
|
||||
|
||||
else
|
||||
|
||||
|
||||
|
||||
# CREATE ~/.ssb/secret.dunikey
|
||||
ssbpub=$(cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
|
||||
ssbpriv=$(cat ~/.ssb/secret | grep private\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
|
||||
g1pub=$(echo $ssbpub | base64 -d | base58)
|
||||
g1priv=$(echo $ssbpriv | base64 -d | base58)
|
||||
|
||||
cat > ~/.ssb/secret.dunikey <<EOF
|
||||
Type: PubSec
|
||||
Version: 1
|
||||
pub: $g1pub
|
||||
sec: $g1priv
|
||||
EOF
|
||||
fi
|
|
@ -0,0 +1,162 @@
|
|||
#!/bin/bash
|
||||
################################################################################
|
||||
# Authors:
|
||||
# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
|
||||
# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519)
|
||||
# Version: 1.0
|
||||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||||
###########################################################################################
|
||||
# ADD G1 Layer 10 LOVE to message writer you like !
|
||||
# INSTALL silkaj sbotc
|
||||
# PREVENT DOUBLE PAYEMENT
|
||||
############################################################################################
|
||||
fn_exists() {
|
||||
# appended double quote is an ugly trick to make sure we do get a string -- if $1 is not a known command, type does not output anything
|
||||
[ `type -t $1`"" == 'file' ]
|
||||
}
|
||||
|
||||
###########################################################################################
|
||||
####################### G1 SSB ACCOUNT MANAGER ############################################
|
||||
###########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
# Let's get G1 public and private keys
|
||||
g1pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
|
||||
g1priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
|
||||
# SSB pubkey
|
||||
ssbpub=$(cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
|
||||
|
||||
############################################################################################
|
||||
#### CHECK LIKE AND SEND LOVE
|
||||
# Let's get G1 account balance
|
||||
echo ""
|
||||
echo "Welcome to the G1 SSB "
|
||||
echo "
|
||||
MMMMMMMMMMMMMNk;'cdxxd:,c0WMMMMMMMMMMMMM
|
||||
MMMMMMMMMMMMMNx,. .;kWMMMMMMMMMMMMM
|
||||
MMMMMMMMMMMMMMMNOdlccld0NMMMMMMMMMMMMMMM
|
||||
MMMMMMMMMMMWXko:,'....',:okXWMMMMMMMMMMM
|
||||
MMMMMMMMMNk:. .cOWMMMMMMMMM
|
||||
MMMMMMMW0: .c0MMMMMMMM
|
||||
MMMMMMWk. 'lxkOOkdc' .cOWMMMMMMM
|
||||
MMMMMMO' 'kNMMMMMMMMNxcoOXWMMMMMMMMM
|
||||
MMMMMNl '0MMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||
MMMMMX; cNMMMMMMMNOkkkkkkkkkkONMMMMM
|
||||
MMMMMNc ;XMMMMMMMNd' .OMMMMM
|
||||
MMMMMWx. cKMMMMMMMWKc. .OMMMMM
|
||||
MMMMMMNo. .lkKXNNXKkc. .OMMMMM
|
||||
MMMMMMMNd. ...... .OMMMMM
|
||||
MMMMMMMMWKl. 'c:. .OMMMMM
|
||||
MMMMMMMMMMWXkc,.. ..,lkXWWO:;OMMMMM
|
||||
MMMMMMMMMMMMMMWX0OxddxO0XWMMMMMMWXNMMMMM
|
||||
MMMMMMMMMMMMMMMMNx;'',dNMMMMMMMMMMMMMMMM
|
||||
MMMMMMMMMMMMMMMMK, '0MMMMMMMMMMMMMMMM
|
||||
MMMMMMMMMMMMMMMMNd. .oNMMMMMMMMMMMMMMMM
|
||||
"
|
||||
sleep 1
|
||||
echo ""
|
||||
echo "You know your SSB pubkey:"
|
||||
echo $ssbpub
|
||||
sleep 1
|
||||
echo ""
|
||||
echo "...but did you know it is also a valid G1 wallet?"
|
||||
echo $g1pub
|
||||
sleep 2
|
||||
echo ""
|
||||
echo "Let's check the current balance of your wallet!"
|
||||
sleep 2
|
||||
echo ""
|
||||
echo "We are interrogating the G1 blockchain to check if anyone has already sent G1..."
|
||||
sleep 1
|
||||
echo ""
|
||||
echo "A moment please..."
|
||||
echo ""
|
||||
sleep 1
|
||||
|
||||
duniter_server="duniter-g1.p2p.legal:443"
|
||||
echo "Testing server $duniter_server..."
|
||||
echo ""
|
||||
silkaj -p "$duniter_server" balance $g1pub 2>/dev/null
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
duniter_server="g1.duniter.org:443"
|
||||
echo "Testing server $duniter_server..."
|
||||
echo ""
|
||||
silkaj -p "$duniter_server" balance $g1pub 2>/dev/null
|
||||
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
echo "The server did not respond well. Please try again."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Have any money? Then let's send G1love. Press ENTER to continue. " && read
|
||||
###########################################################################################
|
||||
self=$(sbotc whoami | jq -r .id) || exit 1
|
||||
ssb_dir=~/.${ssb_appname:-ssb}
|
||||
id_part=$(echo "$self" | sed 's/\//_/g' | tail -c +2 | head -c 9)
|
||||
state_file=$ssb_dir/likes-g1-$id_part.ts
|
||||
|
||||
if [ -s "$state_file" ]
|
||||
then last_ts=$(cat "$state_file") || exit 1
|
||||
else
|
||||
last_ts=$(date -u +%s%N | cut -b1-13)
|
||||
last_ts=$((last_ts - 3600000)) # timestamp from 1h ago
|
||||
|
||||
#else last_ts=null
|
||||
fi
|
||||
|
||||
process_msg() {
|
||||
msg=$1
|
||||
target_id=$(printf %s "$msg" | jq -r '.value?.content?.vote?.link') || return 1
|
||||
target_msg=$(sbotc -e get "$target_id") || return 1
|
||||
target_author=$(printf %s "$target_msg" | jq -r .author) || return 1
|
||||
root_id=$(printf %s "$target_msg" | jq -r .content?.root) || return 1
|
||||
[[ $root_id == "null" ]] && root_id=$target_id
|
||||
g1_author=$(echo $target_author | cut -d '.' -f 1 | cut -d '@' -f2 | base64 -d | base58)
|
||||
}
|
||||
|
||||
sbotc query.read '{"query":[{"$filter":{"value":{"author":"'"$self"'","content":{"type":"vote", "vote":{"expression":"Like"}},"timestamp":{"$gt":'"$last_ts"'}}}}]}' | while read -r msg
|
||||
do
|
||||
if ! ts=$(printf %s "$msg" | jq -r .value.timestamp)
|
||||
then
|
||||
printf 'Unable to get message timestamp\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! echo "$ts" > "$state_file"~
|
||||
then
|
||||
printf 'Unable to write to backup state file.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! process_msg "$msg"
|
||||
then
|
||||
msg_id=$(printf %s "$msg" | jq -r .key)
|
||||
printf 'Unable to process message %s\n' "$msg_id" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf 'Message: %s ( Author: %s )\n' "$target_id" "$target_author"
|
||||
if [[ $g1_author != $g1pub ]]; then
|
||||
sleep 3
|
||||
#printf '%s\n' "silkaj -af --file ~/.ssb/secret.dunikey tx --output $g1_author --amountUD 0.1 --comment _SSB:LIKE:$target_id"
|
||||
|
||||
# silkaj -p "$duniter_server" -af --file ~/.ssb/secret.dunikey tx --output $g1_author --amountUD 0.1 --comment "_SSB:LIKE:$target_id" -y 2>/dev/null
|
||||
|
||||
|
||||
#thank_you_msg="Hi there! I liked your post and thus sent you Ğ1 #libremoney. We don\'t really know how you may be able to use it but, hey, that is still money, right? Cheers!"
|
||||
|
||||
sbotc publish '{"type":"post","text":"Thanks for this post ; I have just sent you G1 #libremoney. Claim it! ", "branch": "'"$target_id"'", "root": "'"$root_id"'"}'
|
||||
|
||||
#sleep 60 # DO NOT OVER CHARGE DUNITER
|
||||
else
|
||||
echo "I LIKE MY MESSAGE $target_id"
|
||||
fi
|
||||
if ! mv "$state_file"~ "$state_file"
|
||||
then
|
||||
msg_id=$(printf %s "$msg" | jq -r .key)
|
||||
printf 'Unable to write to state file. Update state file manually to prevent %s from being processed twice.\n' "$msg_id" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue