Skip to content

Commit b9ca967

Browse files
committed
Fix test case and update types
1 parent 0e6d193 commit b9ca967

File tree

10 files changed

+41
-23
lines changed

10 files changed

+41
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def transfer(cli: client.Client, sender: local_account.LocalAccount, receipt: st
4747
now_seconds = int(node_info.get('now_seconds'))
4848
# expired after 12 hours
4949
expiration_timestamp_secs = now_seconds + 43200
50-
raw_txn = types.RawTransaction(
50+
raw_txn = types.RawUserTransaction(
5151
sender=sender.account_address,
5252
sequence_number=seq_num,
5353
payload=script,

examples/p2p_transfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def transfer(cli: client.Client, sender: local_account.LocalAccount, receipt: st
2222
now_seconds = int(node_info.get('now_seconds'))
2323
# expired after 12 hours
2424
expiration_timestamp_secs = now_seconds + 43200
25-
raw_txn = types.RawTransaction(
25+
raw_txn = types.RawUserTransaction(
2626
sender=sender.account_address,
2727
sequence_number=seq_num,
2828
payload=script,

examples/p2p_transfer_by_address.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def transfer(cli: client.Client, sender: local_account.LocalAccount, receiver: t
2121
now_seconds = int(node_info.get('now_seconds'))
2222
# expired after 12 hours
2323
expiration_timestamp_secs = now_seconds + 43200
24-
raw_txn = types.RawTransaction(
24+
raw_txn = types.RawUserTransaction(
2525
sender=sender.account_address,
2626
sequence_number=seq_num,
2727
payload=script,

examples/rotate_auth_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def rotate_key(cli: client.Client, account: local_account.LocalAccount, auth_key: auth_key.AuthKey):
1111
seq_num = cli.get_account_sequence(account.account_address)
1212
script = stdlib.encode_rotate_authentication_key_script(new_auth_key.data)
13-
raw_txn = types.RawTransaction(
13+
raw_txn = types.RawUserTransaction(
1414
sender=account.account_address,
1515
sequence_number=seq_num,
1616
payload=types.TransactionPayload__Script(script),

examples/swap_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def send_txn(cli, sender, script_funtion):
1313
expiration_timestamp_secs = now_seconds + 43200
1414
seq_num = cli.get_account_sequence(
1515
"0x"+sender.account_address.bcs_serialize().hex())
16-
raw_txn = RawTransaction(
16+
raw_txn = RawUserTransaction(
1717
sender=sender.account_address,
1818
sequence_number=seq_num,
1919
payload=script_funtion,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="starcoin-sdk-python",
12-
version="1.4.0",
12+
version="1.4.1",
1313
description="The Python Client SDK for Starcoin",
1414
long_description=long_description,
1515
long_description_content_type='text/markdown',

starcoin/sdk/local_account.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def private_key_hex(self) -> str:
7272
def compliance_public_key_bytes(self) -> bytes:
7373
return utils.public_key_bytes(self.compliance_key.public_key())
7474

75-
def sign(self, txn: starcoin_types.RawTransaction) -> starcoin_types.SignedUserTransaction:
76-
"""Create signed transaction for given raw transaction"""
75+
def sign(self, txn: starcoin_types.RawUserTransaction) -> starcoin_types.SignedUserTransaction:
76+
"""Create signed transaction for given raw user transaction"""
7777
signature = self.private_key.sign(
7878
utils.raw_transaction_signing_msg(txn))
7979
return utils.create_signed_transaction(txn, self.public_key_bytes, signature)

starcoin/sdk/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ def public_key_bytes(public_key: ed25519.Ed25519PublicKey) -> bytes:
9797
def currency_code(code: str) -> starcoin_types.TypeTag:
9898
"""converts currency code string to starcoin_types.TypeTag"""
9999
if isinstance(code, str):
100-
return starcoin_types.TypeTag__Struct(
100+
return starcoin_types.TypeTag__struct(
101101
value=starcoin_types.StructTag(
102102
address=account_address(CORE_CODE_ADDRESS),
103103
module=starcoin_types.Identifier(code),
104104
name=starcoin_types.Identifier(code),
105-
type_params=[],
105+
type_args=[],
106106
)
107107
)
108108

@@ -112,12 +112,12 @@ def currency_code(code: str) -> starcoin_types.TypeTag:
112112
def currency_user_code(address: str, code: str) -> starcoin_types.TypeTag:
113113
"""converts currency code string to starcoin_types.TypeTag"""
114114
if isinstance(code, str):
115-
return starcoin_types.TypeTag__Struct(
115+
return starcoin_types.TypeTag__struct(
116116
value=starcoin_types.StructTag(
117117
address=account_address(address),
118118
module=starcoin_types.Identifier(code),
119119
name=starcoin_types.Identifier(code),
120-
type_params=[],
120+
type_args=[],
121121
)
122122
)
123123

@@ -127,15 +127,15 @@ def currency_user_code(address: str, code: str) -> starcoin_types.TypeTag:
127127
def type_tag_to_str(code: starcoin_types.TypeTag) -> str:
128128
"""converts currency code TypeTag into string"""
129129

130-
if isinstance(code, starcoin_types.TypeTag__Struct):
131-
if isinstance(self, TypeTag__Struct):
130+
if isinstance(code, starcoin_types.TypeTag__struct):
131+
if isinstance(self, TypeTag__struct):
132132
return self.value.name.value
133133
raise TypeError(f"unknown currency code type: {self}")
134134
raise TypeError(f"unknown currency code type: {code}")
135135

136136

137137
def create_signed_transaction(
138-
txn: starcoin_types.RawTransaction, public_key: bytes, signature: bytes
138+
txn: starcoin_types.RawUserTransaction, public_key: bytes, signature: bytes
139139
) -> starcoin_types.SignedUserTransaction:
140140
"""create single signed `starcoin_types.SignedTransaction`"""
141141
return starcoin_types.SignedUserTransaction(
@@ -147,8 +147,8 @@ def create_signed_transaction(
147147
)
148148

149149

150-
def raw_transaction_signing_msg(txn: starcoin_types.RawTransaction) -> bytes:
151-
"""create signing message from given `starcoin_types.RawTransaction`"""
150+
def raw_transaction_signing_msg(txn: starcoin_types.RawUserTransaction) -> bytes:
151+
"""create signing message from given `starcoin_types.RawUserTransaction`"""
152152
return starcoin_hash_seed(b"RawUserTransaction") + txn.bcs_serialize()
153153

154154

@@ -188,7 +188,7 @@ def verify_signed_message(signed_message_hex: str) -> starcoin_types.SignedMessa
188188
public_key = signed_message.authenticator.public_key.value
189189
signature = signed_message.authenticator.signature.value
190190
data = starcoin_hash_seed(b"SigningMessage") + \
191-
signed_message.signing_message.bcs_serialize()
191+
signed_message.message.bcs_serialize()
192192
ed = ed25519.Ed25519PublicKey.from_public_bytes(public_key)
193193
ed.verify(signature, data)
194194
except Exception as e:

starcoin/starcoin_types/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def bcs_deserialize(input: bytes) -> 'AccountAddress':
3434
if buffer:
3535
raise st.DeserializationError("Some input bytes were not read")
3636
return v
37+
38+
@staticmethod
39+
def from_hex(addr: str) -> 'AccountAddress':
40+
"""Create an account address from bytes."""
41+
return AccountAddress(tuple(st.uint8(x) for x in bytes.fromhex(addr)))
3742

3843

3944
@dataclass(frozen=True)
@@ -280,7 +285,7 @@ def bcs_deserialize(input: bytes) -> 'Ed25519Signature':
280285
@dataclass(frozen=True)
281286
class EventHandle:
282287
count: st.uint64
283-
key: "EventKey"
288+
key: bytes
284289

285290
def bcs_serialize(self) -> bytes:
286291
return bcs.serialize(self, EventHandle)
@@ -295,8 +300,9 @@ def bcs_deserialize(input: bytes) -> 'EventHandle':
295300

296301
@dataclass(frozen=True)
297302
class EventKey:
298-
value: bytes
299-
303+
salt: st.uint64
304+
address: AccountAddress
305+
300306
def bcs_serialize(self) -> bytes:
301307
return bcs.serialize(self, EventKey)
302308

@@ -969,3 +975,17 @@ def bcs_deserialize(input: bytes) -> 'WriteSetMut':
969975
if buffer:
970976
raise st.DeserializationError("Some input bytes were not read")
971977
return v
978+
979+
@dataclass(frozen=True)
980+
class BalanceResource:
981+
token: st.uint128
982+
983+
def bcs_serialize(self) -> bytes:
984+
return bcs.serialize(self, BalanceResource)
985+
986+
@staticmethod
987+
def bcs_deserialize(input: bytes) -> 'BalanceResource':
988+
v, buffer = bcs.deserialize(input, BalanceResource)
989+
if buffer:
990+
raise st.DeserializationError("Some input bytes were not read")
991+
return v

tests/test_jsonrpc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def test_apis():
1717
assert auth_key == "0000000000000000000000000000000000000000000000000000000000000001"
1818
assert isinstance(cli.get_account_sequence(
1919
"0x00000000000000000000000000000001"), int) is True
20-
assert cli.get_account_token(
21-
"0x00000000000000000000000000000001", "STC", "STC") == 0
2220
tx = cli.get_transaction(
2321
"0xd15e5d2d306c898effe61ce9cddb976b8e5a5c24ef67fb5c3a02ca7f156b738b")
2422
payload = tx.get("user_transaction").get("raw_txn").get("payload")

0 commit comments

Comments
 (0)