Skip to content

Commit ce00e2c

Browse files
authored
Merge pull request #32 from scrtlabs/main
Fix some issues for SecretPath
2 parents 346c53a + 6ca6784 commit ce00e2c

File tree

135 files changed

+12321
-962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+12321
-962
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ license = "MIT"
1717
packages = [{ include = "secret_sdk" }]
1818
readme = "README.md"
1919
repository = "https://github.com/stephanegg/secret-sdk-python"
20-
version = "1.7.1"
20+
version = "1.8.0"
2121

2222
[tool.poetry.dependencies]
2323
aiohttp = "^3.7.3"

scripts/generate_protobuf.sh

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o errexit -o nounset -o pipefail
44
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
55

66
rm -rf "${SCRIPT_PATH}/SecretNetwork"
7-
git clone --depth 1 --branch v1.7.1 https://github.com/scrtlabs/SecretNetwork "${SCRIPT_PATH}/SecretNetwork"
7+
git clone --depth 1 --branch v1.15.0-beta.0 https://github.com/scrtlabs/SecretNetwork "${SCRIPT_PATH}/SecretNetwork"
88

99
SECRET_DIR="${SCRIPT_PATH}/SecretNetwork/proto"
1010
SECRET_THIRD_PARTY_DIR="${SCRIPT_PATH}/SecretNetwork/third_party/proto"
@@ -23,4 +23,4 @@ protoc \
2323
--proto_path=${SECRET_DIR} \
2424
--proto_path=${SECRET_THIRD_PARTY_DIR} \
2525
--python_betterproto_out="${OUT_DIR}" \
26-
$(find ${SECRET_DIR} ${SECRET_THIRD_PARTY_DIR} -path -prune -o -name '*.proto' -print0 | xargs -0)
26+
$(find ${SECRET_DIR} ${SECRET_THIRD_PARTY_DIR} -path -prune -o -name '*.proto' -print0 | xargs -0)

secret_sdk/client/lcd/api/tx.py

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,78 @@ def decrypt_txs_response(self, txs_response) -> TxInfo:
222222

223223
txs_response = txs_response['tx_response']
224224
raw_log = txs_response['raw_log']
225-
json_log = None
226-
array_log = None
225+
json_log = []
226+
array_log = []
227+
events = txs_response['events']
227228

228229
code = txs_response['code']
229-
if code == 0 and raw_log != '':
230-
_json_log = json.loads(raw_log)
231-
json_log = []
232-
for i, log in enumerate(_json_log):
233-
if 'msg_index' not in log or not log['msg_index']:
234-
# See https://github.com/cosmos/cosmos-sdk/pull/11147
235-
log['msg_index'] = i
236-
json_log.append(TxLog(i, log.get('log'), log['events']))
237-
array_log = self.decrypt_logs(_json_log, nonces)
230+
231+
if code == 0 and raw_log == "":
232+
for event in events:
233+
event_attributes = event.get('attributes', [])
234+
msg_index_attr = next((attr for attr in event_attributes if attr.get('key') == 'msg_index'), None)
235+
if not msg_index_attr:
236+
continue
237+
238+
msg_index = int(msg_index_attr.get('value'))
239+
240+
for attr in event_attributes:
241+
if attr.get('key') == 'msg_index':
242+
continue
243+
244+
# Try to decrypt if the event type is 'wasm'
245+
if event.get('type') == 'wasm':
246+
nonce = nonces[msg_index]
247+
if nonce and len(nonce) == 32:
248+
try:
249+
decrypted_key = self.decrypt_data_field(base64.b64decode(attr['key']), nonce).decode('utf-8').strip()
250+
attr['key'] = decrypted_key
251+
except Exception:
252+
pass
253+
254+
try:
255+
decrypted_value = self.decrypt_data_field(base64.b64decode(attr['value']), nonce).decode('utf-8').strip()
256+
attr['value'] = decrypted_value
257+
except Exception:
258+
pass
259+
260+
# Prepare entry for array_log
261+
entry_to_push = {
262+
'msg': msg_index,
263+
'type': event['type'],
264+
'key': attr['key'],
265+
'value': attr['value'],
266+
}
267+
268+
# Append to array_log if entry_to_push is unique
269+
if not any(entry == entry_to_push for entry in array_log):
270+
array_log.append(entry_to_push)
271+
272+
# Prepare entry for json_log
273+
json_log_msg_index_entry = next((log for log in json_log if log['msg_index'] == msg_index), None)
274+
if not json_log_msg_index_entry:
275+
json_log.append({
276+
'msg_index': msg_index,
277+
'events': [
278+
{
279+
'type': event['type'],
280+
'attributes': [{'key': attr['key'], 'value': attr['value']}]
281+
}
282+
]
283+
})
284+
else:
285+
json_log_event_entry = next((log for log in json_log_msg_index_entry['events'] if log['type'] == event['type']), None)
286+
if not json_log_event_entry:
287+
json_log_msg_index_entry['events'].append({
288+
'type': event['type'],
289+
'attributes': [{'key': attr['key'], 'value': attr['value']}]
290+
})
291+
else:
292+
attribute_to_push = {'key': attr['key'], 'value': attr['value']}
293+
294+
# Add to attributes if not already present
295+
if not any(attr == attribute_to_push for attr in json_log_event_entry['attributes']):
296+
json_log_event_entry['attributes'].append(attribute_to_push)
238297
elif code != 0 and raw_log != '':
239298
try:
240299
error_message_rgx = re.compile(
@@ -292,6 +351,7 @@ def decrypt_txs_response(self, txs_response) -> TxInfo:
292351
tx=decoded_tx,
293352
tx_bytes=txs_response['tx'].get('value') if txs_response['tx'] else None,
294353
rawlog=raw_log,
354+
events=txs_response['events'],
295355
logs=array_log if array_log else json_log,
296356
data=data,
297357
gas_used=int(txs_response['gas_used']),
@@ -392,7 +452,7 @@ async def broadcast_adapter(self, tx: Tx, mode: BroadcastMode, options: Broadcas
392452
broadcast_result = await BaseAsyncAPI._try_await(self.broadcast_async(tx_encoded, options))
393453
if mode == BroadcastMode.BROADCAST_MODE_SYNC:
394454
broadcast_result = await BaseAsyncAPI._try_await(self.broadcast_sync(tx_encoded, options))
395-
if not broadcast_result.code != 0:
455+
if broadcast_result.code != 0:
396456
raise Exception(f"Broadcasting transaction failed with code {broadcast_result.code} (codespace: ${broadcast_result.codespace}).Log: {broadcast_result.raw_log}")
397457

398458
return broadcast_result

secret_sdk/core/tx.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from secret_sdk.protobuf.cosmos.tx.v1beta1 import Tx as Tx_pb
1818
from secret_sdk.protobuf.cosmos.tx.v1beta1 import TxBody as TxBody_pb
1919
from secret_sdk.util.encrypt_utils import EncryptionUtils
20+
from secret_sdk.protobuf.tendermint.abci import Event
2021

2122
from secret_sdk.core.compact_bit_array import CompactBitArray
2223
from secret_sdk.core.fee import Fee
@@ -592,6 +593,9 @@ class TxInfo(JSONSerializable):
592593
logs: Optional[List[TxLog]] = attr.ib()
593594
"""Event log information."""
594595

596+
events: Optional[List[Event]] = attr.ib()
597+
"""All events emitted during transaction processing (including ante handler events)."""
598+
595599
gas_wanted: int = attr.ib(converter=int)
596600
"""Gas requested by transaction."""
597601

@@ -620,6 +624,7 @@ def to_data(self) -> dict:
620624
"txhash": self.txhash,
621625
"rawlog": self.rawlog,
622626
"logs": [log.to_data() for log in self.logs] if self.logs else None,
627+
"events" : self.events,
623628
"gas_wanted": str(self.gas_wanted),
624629
"gas_used": str(self.gas_used),
625630
"timestamp": self.timestamp,
@@ -639,6 +644,7 @@ def from_data(cls, data: dict) -> TxInfo:
639644
data.get("txhash"),
640645
data.get("raw_log"),
641646
parse_tx_logs(data.get("logs")),
647+
data.get("events"),
642648
data.get("gas_wanted"),
643649
data.get("gas_used"),
644650
Tx.from_data(data.get("tx")),
@@ -655,6 +661,7 @@ def to_proto(self) -> TxResponse_pb:
655661
proto.txhash = self.txhash
656662
proto.raw_log = self.rawlog
657663
proto.logs = [log.to_proto() for log in self.logs] if self.logs else None
664+
proto.events = self.events
658665
proto.gas_wanted = self.gas_wanted
659666
proto.gas_used = self.gas_used
660667
proto.timestamp = self.timestamp
@@ -670,6 +677,7 @@ def from_proto(cls, proto: TxResponse_pb) -> TxInfo:
670677
txhash=proto.txhash,
671678
rawlog=proto.raw_log,
672679
logs=parse_tx_logs_proto(proto.logs),
680+
events=proto.events,
673681
gas_wanted=proto.gas_wanted,
674682
gas_used=proto.gas_used,
675683
timestamp=proto.timestamp,

secret_sdk/core/wasm/msgs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def to_proto(self) -> MsgExecuteContract_pb:
249249

250250
return MsgExecuteContract_pb(
251251
sender=address_to_bytes(self.sender),
252+
sender_address=self.sender,
252253
contract=address_to_bytes(self.contract),
253254
msg=self.msg_encrypted,
254255
sent_funds=self.sent_funds.to_proto(),

secret_sdk/protobuf/amino/__init__.py

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

secret_sdk/protobuf/cosmos/app/__init__.py

Whitespace-only changes.

secret_sdk/protobuf/cosmos/app/runtime/__init__.py

Whitespace-only changes.

secret_sdk/protobuf/cosmos/app/runtime/v1alpha1/__init__.py

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)