Skip to content

Commit 1bb9912

Browse files
Merge pull request #1171 from mintlayer:feature/wallet-delegation-shares
Feature/wallet delegation shares
2 parents a144901 + fc77752 commit 1bb9912

File tree

15 files changed

+621
-171
lines changed

15 files changed

+621
-171
lines changed

chainstate/src/rpc/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use chainstate_types::BlockIndex;
2424
use common::{
2525
chain::{
2626
tokens::{RPCTokenInfo, TokenId},
27-
PoolId, SignedTransaction, Transaction,
27+
DelegationId, PoolId, SignedTransaction, Transaction,
2828
},
2929
primitives::{Amount, BlockHeight, Id},
3030
};
@@ -110,6 +110,13 @@ trait ChainstateRpc {
110110
#[method(name = "stake_pool_pledge")]
111111
async fn stake_pool_pledge(&self, pool_id: PoolId) -> RpcResult<Option<Amount>>;
112112

113+
#[method(name = "delegation_share")]
114+
async fn delegation_share(
115+
&self,
116+
pool_id: PoolId,
117+
delegation_id: DelegationId,
118+
) -> RpcResult<Option<Amount>>;
119+
113120
/// Get token information
114121
#[method(name = "token_info")]
115122
async fn token_info(&self, token_id: TokenId) -> RpcResult<Option<RPCTokenInfo>>;
@@ -246,6 +253,17 @@ impl ChainstateRpcServer for super::ChainstateHandle {
246253
)
247254
}
248255

256+
async fn delegation_share(
257+
&self,
258+
pool_id: PoolId,
259+
delegation_id: DelegationId,
260+
) -> RpcResult<Option<Amount>> {
261+
rpc::handle_result(
262+
self.call(move |this| this.get_stake_pool_delegation_share(pool_id, delegation_id))
263+
.await,
264+
)
265+
}
266+
249267
async fn token_info(&self, token_id: TokenId) -> RpcResult<Option<RPCTokenInfo>> {
250268
rpc::handle_result(self.call(move |this| this.get_token_info_for_rpc(token_id)).await)
251269
}

test/functional/test_framework/wallet_cli_controller.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
ONE_MB = 2**20
2828
READ_TIMEOUT_SEC = 30
29+
DEFAULT_ACCOUNT_INDEX = 0
2930

3031
@dataclass
3132
class UtxoOutpoint:
@@ -35,6 +36,15 @@ class UtxoOutpoint:
3536
def __str__(self):
3637
return f'tx({self.id},{self.index})'
3738

39+
@dataclass
40+
class PoolData:
41+
pool_id: str
42+
balance: int
43+
44+
@dataclass
45+
class DelegationData:
46+
delegation_id: str
47+
balance: int
3848

3949
class WalletCliController:
4050

@@ -192,15 +202,42 @@ async def issue_new_nft(self,
192202
return None
193203

194204
async def create_stake_pool(self,
195-
amount: str,
196-
cost_per_block: str,
197-
margin_ratio_per_thousand: str,
205+
amount: int,
206+
cost_per_block: int,
207+
margin_ratio_per_thousand: float,
198208
decommission_key: Optional[str] = '') -> str:
199209
return await self._write_command(f"createstakepool {amount} {cost_per_block} {margin_ratio_per_thousand} {decommission_key}\n")
200210

211+
async def list_pool_ids(self) -> List[PoolData]:
212+
output = await self._write_command("listpoolids\n")
213+
pattern = r'Pool Id: ([a-zA-Z0-9]+), Balance: (\d+),'
214+
matches = re.findall(pattern, output)
215+
return [PoolData(pool_id, int(balance)) for pool_id, balance in matches]
216+
217+
async def create_delegation(self, address: str, pool_id: str) -> Optional[str]:
218+
output = await self._write_command(f"createdelegation {address} {pool_id}\n")
219+
pattern = r'Delegation id: ([a-zA-Z0-9]+)'
220+
match = re.search(pattern, output)
221+
if match:
222+
return match.group(1)
223+
else:
224+
return None
225+
226+
async def stake_delegation(self, amount: int, delegation_id: str) -> str:
227+
return await self._write_command(f"delegatestaking {amount} {delegation_id}\n")
228+
229+
async def list_delegation_ids(self) -> List[DelegationData]:
230+
output = await self._write_command("listdelegationids\n")
231+
pattern = r'Delegation Id: ([a-zA-Z0-9]+), Balance: (\d+)'
232+
matches = re.findall(pattern, output)
233+
return [DelegationData(delegation_id, int(balance)) for delegation_id, balance in matches]
234+
201235
async def sync(self) -> str:
202236
return await self._write_command("syncwallet\n")
203237

238+
async def start_staking(self) -> str:
239+
return await self._write_command(f"startstaking\n")
240+
204241
async def get_addresses_usage(self) -> str:
205242
return await self._write_command("showreceiveaddresses\n")
206243

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class UnicodeOnWindowsError(ValueError):
131131
'wallet_get_address_usage.py',
132132
'wallet_tokens.py',
133133
'wallet_nfts.py',
134+
'wallet_delegations.py',
134135
'mempool_basic_reorg.py',
135136
'mempool_eviction.py',
136137
'mempool_ibd.py',

0 commit comments

Comments
 (0)