Skip to content

Commit

Permalink
Merge pull request #1171 from mintlayer:feature/wallet-delegation-shares
Browse files Browse the repository at this point in the history
Feature/wallet delegation shares
  • Loading branch information
TheQuantumPhysicist authored Sep 13, 2023
2 parents a144901 + fc77752 commit 1bb9912
Show file tree
Hide file tree
Showing 15 changed files with 621 additions and 171 deletions.
20 changes: 19 additions & 1 deletion chainstate/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use chainstate_types::BlockIndex;
use common::{
chain::{
tokens::{RPCTokenInfo, TokenId},
PoolId, SignedTransaction, Transaction,
DelegationId, PoolId, SignedTransaction, Transaction,
},
primitives::{Amount, BlockHeight, Id},
};
Expand Down Expand Up @@ -110,6 +110,13 @@ trait ChainstateRpc {
#[method(name = "stake_pool_pledge")]
async fn stake_pool_pledge(&self, pool_id: PoolId) -> RpcResult<Option<Amount>>;

#[method(name = "delegation_share")]
async fn delegation_share(
&self,
pool_id: PoolId,
delegation_id: DelegationId,
) -> RpcResult<Option<Amount>>;

/// Get token information
#[method(name = "token_info")]
async fn token_info(&self, token_id: TokenId) -> RpcResult<Option<RPCTokenInfo>>;
Expand Down Expand Up @@ -246,6 +253,17 @@ impl ChainstateRpcServer for super::ChainstateHandle {
)
}

async fn delegation_share(
&self,
pool_id: PoolId,
delegation_id: DelegationId,
) -> RpcResult<Option<Amount>> {
rpc::handle_result(
self.call(move |this| this.get_stake_pool_delegation_share(pool_id, delegation_id))
.await,
)
}

async fn token_info(&self, token_id: TokenId) -> RpcResult<Option<RPCTokenInfo>> {
rpc::handle_result(self.call(move |this| this.get_token_info_for_rpc(token_id)).await)
}
Expand Down
43 changes: 40 additions & 3 deletions test/functional/test_framework/wallet_cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

ONE_MB = 2**20
READ_TIMEOUT_SEC = 30
DEFAULT_ACCOUNT_INDEX = 0

@dataclass
class UtxoOutpoint:
Expand All @@ -35,6 +36,15 @@ class UtxoOutpoint:
def __str__(self):
return f'tx({self.id},{self.index})'

@dataclass
class PoolData:
pool_id: str
balance: int

@dataclass
class DelegationData:
delegation_id: str
balance: int

class WalletCliController:

Expand Down Expand Up @@ -192,15 +202,42 @@ async def issue_new_nft(self,
return None

async def create_stake_pool(self,
amount: str,
cost_per_block: str,
margin_ratio_per_thousand: str,
amount: int,
cost_per_block: int,
margin_ratio_per_thousand: float,
decommission_key: Optional[str] = '') -> str:
return await self._write_command(f"createstakepool {amount} {cost_per_block} {margin_ratio_per_thousand} {decommission_key}\n")

async def list_pool_ids(self) -> List[PoolData]:
output = await self._write_command("listpoolids\n")
pattern = r'Pool Id: ([a-zA-Z0-9]+), Balance: (\d+),'
matches = re.findall(pattern, output)
return [PoolData(pool_id, int(balance)) for pool_id, balance in matches]

async def create_delegation(self, address: str, pool_id: str) -> Optional[str]:
output = await self._write_command(f"createdelegation {address} {pool_id}\n")
pattern = r'Delegation id: ([a-zA-Z0-9]+)'
match = re.search(pattern, output)
if match:
return match.group(1)
else:
return None

async def stake_delegation(self, amount: int, delegation_id: str) -> str:
return await self._write_command(f"delegatestaking {amount} {delegation_id}\n")

async def list_delegation_ids(self) -> List[DelegationData]:
output = await self._write_command("listdelegationids\n")
pattern = r'Delegation Id: ([a-zA-Z0-9]+), Balance: (\d+)'
matches = re.findall(pattern, output)
return [DelegationData(delegation_id, int(balance)) for delegation_id, balance in matches]

async def sync(self) -> str:
return await self._write_command("syncwallet\n")

async def start_staking(self) -> str:
return await self._write_command(f"startstaking\n")

async def get_addresses_usage(self) -> str:
return await self._write_command("showreceiveaddresses\n")

Expand Down
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class UnicodeOnWindowsError(ValueError):
'wallet_get_address_usage.py',
'wallet_tokens.py',
'wallet_nfts.py',
'wallet_delegations.py',
'mempool_basic_reorg.py',
'mempool_eviction.py',
'mempool_ibd.py',
Expand Down
Loading

0 comments on commit 1bb9912

Please sign in to comment.