|
17 | 17 | # along with Polkascan. If not, see <http://www.gnu.org/licenses/>.
|
18 | 18 |
|
19 | 19 | from datetime import datetime
|
| 20 | +from hashlib import blake2b |
| 21 | + |
20 | 22 | from scalecodec.base import ScaleType, ScaleBytes
|
21 | 23 | from scalecodec.exceptions import InvalidScaleTypeValueException
|
22 | 24 |
|
@@ -796,9 +798,14 @@ class Linkage(Struct):
|
796 | 798 |
|
797 | 799 | class AccountId(H256):
|
798 | 800 |
|
| 801 | + def __init__(self, data=None, sub_type=None, metadata=None): |
| 802 | + self.ss58_address = None |
| 803 | + super().__init__(data, sub_type, metadata) |
| 804 | + |
799 | 805 | def process_encode(self, value):
|
800 | 806 | if value[0:2] != '0x' and len(value) == 47:
|
801 | 807 | from scalecodec.utils.ss58 import ss58_decode
|
| 808 | + self.ss58_address = value |
802 | 809 | value = '0x{}'.format(ss58_decode(value))
|
803 | 810 | return super().process_encode(value)
|
804 | 811 |
|
@@ -1949,3 +1956,28 @@ def process_encode(self, value):
|
1949 | 1956 |
|
1950 | 1957 | return data
|
1951 | 1958 |
|
| 1959 | + |
| 1960 | +class MultiAccountId(AccountId): |
| 1961 | + |
| 1962 | + @classmethod |
| 1963 | + def create_from_account_list(cls, accounts, threshold): |
| 1964 | + from scalecodec.utils.ss58 import ss58_decode |
| 1965 | + |
| 1966 | + account_ids = [] |
| 1967 | + for account in accounts: |
| 1968 | + if account[0:2] != '0x': |
| 1969 | + account = '0x{}'.format(ss58_decode(account)) |
| 1970 | + account_ids.append(account) |
| 1971 | + |
| 1972 | + account_list_cls = cls.get_decoder_class('Vec<AccountId>') |
| 1973 | + account_list_data = account_list_cls.encode(sorted(account_ids)) |
| 1974 | + threshold_data = cls.get_decoder_class("u16").encode(threshold) |
| 1975 | + |
| 1976 | + multi_account_id = "0x{}".format(blake2b( |
| 1977 | + b"modlpy/utilisuba" + bytes(account_list_data.data) + bytes(threshold_data.data), digest_size=32 |
| 1978 | + ).digest().hex()) |
| 1979 | + |
| 1980 | + multi_account_obj = cls() |
| 1981 | + multi_account_obj.encode(multi_account_id) |
| 1982 | + |
| 1983 | + return multi_account_obj |
0 commit comments