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

Feat/balance manipuration #67

Merged
merged 12 commits into from
Jun 26, 2023
Merged

Feat/balance manipuration #67

merged 12 commits into from
Jun 26, 2023

Conversation

shunsukew
Copy link
Collaborator

@shunsukew shunsukew commented May 11, 2023

Resolve #65

User's free balance manipuration.
Because

  1. balance logic is inside runtime (Only extrinsic can modify the state)
  2. Anyone needs be able to manipulate balances without creating sig & extrinsic (tx fee should not be charged).

Solution here is creating unsigned extrinsic and put it in transaction pool when RPC method is called.

Custom logic added to balances_pallet

For balance manipulation, some custom logic are added to the original pallet_balances (polkadot-v0.9.39).
※ Comment out [swanky node specific] is added to those custom implementations. source code under frame/balances/src other than [swanky node specific] is copied from Substrate.

  1. set_free_balance call
    This is almost same as set_balance. While set_balance alters free_balance and reserved_balance only allowed by RootOrigin, set_free_balance alters free_balance only unless account itself is removed due to Existential Deposit and operation is only allowed by NoneOrigin so that it can accept UnsignedExtrinsic.
  2. validate_unsigned
    Because set_free_balance uses Unsigned Extrinsic, we need validate_unsigned implementation in balances pallet to check validity of them.

How to set free balance

Example Request

curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d   '{                                                                                 feat/balance-manipuration ✭ ✱
     "jsonrpc":"2.0",
      "id":1,
      "method":"balance_setFreeBalance",
      "params": ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 120000000000000000000, null]
    }'

Example Response

{"jsonrpc":"2.0","result":null,"id":1}% 

How to get account info via custom RPC

Example Request

curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d   '{                                                                                 feat/balance-manipuration ✭ ✱
     "jsonrpc":"2.0",
      "id":1,
      "method":"balance_getAccount",
      "params": ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", null]
    }'

Example Response

{"jsonrpc":"2.0","result":{"free":120000000000000000000,"reserved":0,"misc_frozen":0,"fee_frozen":0},"id":1}%

@shunsukew shunsukew marked this pull request as ready for review May 17, 2023 13:56
@codespool
Copy link
Contributor

I couldn't build on mac.
got:

error: failed to run custom build command for `libp2p-core v0.38.0`

Caused by:
  process didn't exit successfully: `/Users/sasapul/Work/astar/swanky-node/target/release/build/libp2p-core-6cc3b51ab4deb7e5/build-script-build` (exit status: 101)

@shunsukew
Copy link
Collaborator Author

shunsukew commented May 18, 2023

failed to run custom build command for `libp2p-core

Some Substrate's current prerequisites seem not to be installed. You need to install them. I think protoc is the one.
https://docs.substrate.io/install/troubleshoot-rust-issues/#installing-cmake-or-protobuf-for-m1-macos-users
https://substrate.stackexchange.com/questions/4015/failed-to-run-custom-build-command-for-libp2p-core-v0-34-0

@PierreOssun PierreOssun merged commit 38def84 into main Jun 26, 2023
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.

Balance manipuration
3 participants