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

WeightV2 #257

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions substrateinterface/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,8 +1886,9 @@ def generate_multisig_account(self, signatories: list, threshold: int) -> MultiA
return multi_sig_account

def create_multisig_extrinsic(self, call: GenericCall, keypair: Keypair, multisig_account: MultiAccountId,
max_weight: Optional[int] = None, era: dict = None, nonce: int = None, tip: int = 0,
tip_asset_id: int = None, signature: Union[bytes, str] = None) -> GenericExtrinsic:
max_weight: Optional[Union[dict, int]] = None, era: dict = None, nonce: int = None,
tip: int = 0, tip_asset_id: int = None, signature: Union[bytes, str] = None
) -> GenericExtrinsic:
"""
Create a Multisig extrinsic that will be signed by one of the signatories. Checks on-chain if the threshold
of the multisig account is reached and try to execute the call accordingly.
Expand All @@ -1911,10 +1912,7 @@ def create_multisig_extrinsic(self, call: GenericCall, keypair: Keypair, multisi
if max_weight is None:
payment_info = self.get_payment_info(call, keypair)
# Check type of weight as per https://github.com/paritytech/substrate/pull/12138
if type(payment_info["weight"]) is dict:
max_weight = payment_info["weight"]["ref_time"]
else:
max_weight = payment_info["weight"]
max_weight = payment_info["weight"]

# Check if call has existing approvals
multisig_details = self.query("Multisig", "Multisigs", [multisig_account.value, call.call_hash])
Expand Down Expand Up @@ -2029,7 +2027,7 @@ def get_payment_info(self, call: GenericCall, keypair: Keypair):
-------
Dict with payment info

E.g. `{'class': 'normal', 'partialFee': 151000000, 'weight': 217238000}`
E.g. `{'class': 'normal', 'partialFee': 151000000, 'weight': {'ref_time': 143322000}}`

"""

Expand Down Expand Up @@ -3558,13 +3556,13 @@ def error_message(self) -> Optional[dict]:
return self.__error_message

@property
def weight(self) -> int:
def weight(self) -> Union[int, dict]:
"""
Contains the actual weight when executing this extrinsic

Returns
-------
int
int (WeightV1) or dict (WeightV2)
"""
if self.__weight is None:
self.process_events()
Expand Down
6 changes: 6 additions & 0 deletions test/test_create_extrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ def test_check_extrinsic_failed_error_message_portable_registry(self):
self.assertEqual(881719000, receipt.weight)
self.assertEqual(receipt.error_message['name'], 'InsufficientBalance')

def test_check_extrinsic_weight_v2(self):
receipt = self.kusama_substrate.retrieve_extrinsic_by_identifier("14963132-10")

self.assertTrue(receipt.is_success)
self.assertEqual({'ref_time': 153773000}, receipt.weight)

def test_check_extrinsic_total_fee_amount(self):
result = ExtrinsicReceipt(
substrate=self.kusama_substrate,
Expand Down