Skip to content

implement combination of withdraw and delegation messages on auto-del…#6

Open
leopoldjoy wants to merge 5 commits into
masterfrom
feature/implement-withdraw-and-delegate-together
Open

implement combination of withdraw and delegation messages on auto-del…#6
leopoldjoy wants to merge 5 commits into
masterfrom
feature/implement-withdraw-and-delegate-together

Conversation

@leopoldjoy

Copy link
Copy Markdown
Contributor

…egate.sh script

Comment thread auto-delegate.sh
if [[($remaining_stake_left_from_last_delegation -gt 10000000)]]
then
# Since it was photinos, set equal to zero since there were no STAKE left following the last transaction
remaining_stake_left_from_last_delegation=0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. I thought it was variable overflow when I set up to be at least > 10000000.
But you are saying that when no stake then it retrieves the photinos.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. .value.coins is an array containing the STAKE (first) and photinos (second) balances. If the STAKE balance is zero than only the photinos balance is returned—hence the much higher number.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cosmos team should learn about good programming practices...
A variable can't return a different type / scope on different scenarios.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Haha :) Yes, they could use an object/dictionary for each of the coin balance names. However my guess is that they used an array since they may want to ultimately allow any number of different coin types/balances in an account

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe but a variable should always return the same type.

Comment thread auto-delegate.sh Outdated
# which will generate the above file (at /etc/systemd/system/myservice.service.d/myenv.conf)

echo "Setting (fake) initial historical interval stake earnings..."
last_10_interval_earnings[0]=100

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should retrieve history from the blockchain directly.

  1. It allows restart of the script
  2. it starts from averaging previous attacks and strange behaviors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, 100% agree, let's add this as a ticket

Comment thread auto-delegate.sh Outdated
echo "About to withdraw (all STAKE) and delegate: $total_to_delegate STAKE"

# Create withdrawal transaction
withdrawal_txn=$(sudo /opt/go/bin/gaiacli --home=/opt/gaiacli tx dist withdraw-rewards --async --is-validator --from=game-of-stake-key-validator4 --chain-id=game_of_stakes_3 --fee=1000photinos --trust-node --generate-only)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we really need async ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, absolutely not, since this is a --generate-only command. Good call! Removed in the most recent commit 👍

Comment thread auto-delegate.sh
delegation_msg=$(echo $delegation_txn | jq -r '.value.msg[0]')

# Combine the delegation message with the withdrawal transaction to create the final transaction (with both messages)
withdrawal_and_delegation_txn=$(echo $withdrawal_txn | jq ".value.msg[1] |= . + $delegation_msg")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice combo !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

:)

Comment thread auto-delegate.sh Outdated
# Combine the delegation message with the withdrawal transaction to create the final transaction (with both messages)
withdrawal_and_delegation_txn=$(echo $withdrawal_txn | jq ".value.msg[1] |= . + $delegation_msg")

echo "Saving generated withdrawal/delegation transaction to $filePath..."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

name filePath is not good.
Maybe: ComboTX or WithdrawDelegateTX

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, true! Fixed in the most recent commit 👍

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.

2 participants