Skip to content
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = "MIT"
packages = [{ include = "secret_sdk" }]
readme = "README.md"
repository = "https://github.com/stephanegg/secret-sdk-python"
version = "1.7.1"
version = "1.8.0"

[tool.poetry.dependencies]
aiohttp = "^3.7.3"
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate_protobuf.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o errexit -o nounset -o pipefail
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

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

SECRET_DIR="${SCRIPT_PATH}/SecretNetwork/proto"
SECRET_THIRD_PARTY_DIR="${SCRIPT_PATH}/SecretNetwork/third_party/proto"
Expand All @@ -23,4 +23,4 @@ protoc \
--proto_path=${SECRET_DIR} \
--proto_path=${SECRET_THIRD_PARTY_DIR} \
--python_betterproto_out="${OUT_DIR}" \
$(find ${SECRET_DIR} ${SECRET_THIRD_PARTY_DIR} -path -prune -o -name '*.proto' -print0 | xargs -0)
$(find ${SECRET_DIR} ${SECRET_THIRD_PARTY_DIR} -path -prune -o -name '*.proto' -print0 | xargs -0)
84 changes: 72 additions & 12 deletions secret_sdk/client/lcd/api/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,78 @@ def decrypt_txs_response(self, txs_response) -> TxInfo:

txs_response = txs_response['tx_response']
raw_log = txs_response['raw_log']
json_log = None
array_log = None
json_log = []
array_log = []
events = txs_response['events']

code = txs_response['code']
if code == 0 and raw_log != '':
_json_log = json.loads(raw_log)
json_log = []
for i, log in enumerate(_json_log):
if 'msg_index' not in log or not log['msg_index']:
# See https://github.com/cosmos/cosmos-sdk/pull/11147
log['msg_index'] = i
json_log.append(TxLog(i, log.get('log'), log['events']))
array_log = self.decrypt_logs(_json_log, nonces)

if code == 0 and raw_log == "":
for event in events:
event_attributes = event.get('attributes', [])
msg_index_attr = next((attr for attr in event_attributes if attr.get('key') == 'msg_index'), None)
if not msg_index_attr:
continue

msg_index = int(msg_index_attr.get('value'))

for attr in event_attributes:
if attr.get('key') == 'msg_index':
continue

# Try to decrypt if the event type is 'wasm'
if event.get('type') == 'wasm':
nonce = nonces[msg_index]
if nonce and len(nonce) == 32:
try:
decrypted_key = self.decrypt_data_field(base64.b64decode(attr['key']), nonce).decode('utf-8').strip()
attr['key'] = decrypted_key
except Exception:
pass

try:
decrypted_value = self.decrypt_data_field(base64.b64decode(attr['value']), nonce).decode('utf-8').strip()
attr['value'] = decrypted_value
except Exception:
pass

# Prepare entry for array_log
entry_to_push = {
'msg': msg_index,
'type': event['type'],
'key': attr['key'],
'value': attr['value'],
}

# Append to array_log if entry_to_push is unique
if not any(entry == entry_to_push for entry in array_log):
array_log.append(entry_to_push)

# Prepare entry for json_log
json_log_msg_index_entry = next((log for log in json_log if log['msg_index'] == msg_index), None)
if not json_log_msg_index_entry:
json_log.append({
'msg_index': msg_index,
'events': [
{
'type': event['type'],
'attributes': [{'key': attr['key'], 'value': attr['value']}]
}
]
})
else:
json_log_event_entry = next((log for log in json_log_msg_index_entry['events'] if log['type'] == event['type']), None)
if not json_log_event_entry:
json_log_msg_index_entry['events'].append({
'type': event['type'],
'attributes': [{'key': attr['key'], 'value': attr['value']}]
})
else:
attribute_to_push = {'key': attr['key'], 'value': attr['value']}

# Add to attributes if not already present
if not any(attr == attribute_to_push for attr in json_log_event_entry['attributes']):
json_log_event_entry['attributes'].append(attribute_to_push)
elif code != 0 and raw_log != '':
try:
error_message_rgx = re.compile(
Expand Down Expand Up @@ -292,6 +351,7 @@ def decrypt_txs_response(self, txs_response) -> TxInfo:
tx=decoded_tx,
tx_bytes=txs_response['tx'].get('value') if txs_response['tx'] else None,
rawlog=raw_log,
events=txs_response['events'],
logs=array_log if array_log else json_log,
data=data,
gas_used=int(txs_response['gas_used']),
Expand Down Expand Up @@ -392,7 +452,7 @@ async def broadcast_adapter(self, tx: Tx, mode: BroadcastMode, options: Broadcas
broadcast_result = await BaseAsyncAPI._try_await(self.broadcast_async(tx_encoded, options))
if mode == BroadcastMode.BROADCAST_MODE_SYNC:
broadcast_result = await BaseAsyncAPI._try_await(self.broadcast_sync(tx_encoded, options))
if not broadcast_result.code != 0:
if broadcast_result.code != 0:
raise Exception(f"Broadcasting transaction failed with code {broadcast_result.code} (codespace: ${broadcast_result.codespace}).Log: {broadcast_result.raw_log}")

return broadcast_result
Expand Down
8 changes: 8 additions & 0 deletions secret_sdk/core/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from secret_sdk.protobuf.cosmos.tx.v1beta1 import Tx as Tx_pb
from secret_sdk.protobuf.cosmos.tx.v1beta1 import TxBody as TxBody_pb
from secret_sdk.util.encrypt_utils import EncryptionUtils
from secret_sdk.protobuf.tendermint.abci import Event

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

events: Optional[List[Event]] = attr.ib()
"""All events emitted during transaction processing (including ante handler events)."""

gas_wanted: int = attr.ib(converter=int)
"""Gas requested by transaction."""

Expand Down Expand Up @@ -620,6 +624,7 @@ def to_data(self) -> dict:
"txhash": self.txhash,
"rawlog": self.rawlog,
"logs": [log.to_data() for log in self.logs] if self.logs else None,
"events" : self.events,
"gas_wanted": str(self.gas_wanted),
"gas_used": str(self.gas_used),
"timestamp": self.timestamp,
Expand All @@ -639,6 +644,7 @@ def from_data(cls, data: dict) -> TxInfo:
data.get("txhash"),
data.get("raw_log"),
parse_tx_logs(data.get("logs")),
data.get("events"),
data.get("gas_wanted"),
data.get("gas_used"),
Tx.from_data(data.get("tx")),
Expand All @@ -655,6 +661,7 @@ def to_proto(self) -> TxResponse_pb:
proto.txhash = self.txhash
proto.raw_log = self.rawlog
proto.logs = [log.to_proto() for log in self.logs] if self.logs else None
proto.events = self.events
proto.gas_wanted = self.gas_wanted
proto.gas_used = self.gas_used
proto.timestamp = self.timestamp
Expand All @@ -670,6 +677,7 @@ def from_proto(cls, proto: TxResponse_pb) -> TxInfo:
txhash=proto.txhash,
rawlog=proto.raw_log,
logs=parse_tx_logs_proto(proto.logs),
events=proto.events,
gas_wanted=proto.gas_wanted,
gas_used=proto.gas_used,
timestamp=proto.timestamp,
Expand Down
1 change: 1 addition & 0 deletions secret_sdk/core/wasm/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def to_proto(self) -> MsgExecuteContract_pb:

return MsgExecuteContract_pb(
sender=address_to_bytes(self.sender),
sender_address=self.sender,
contract=address_to_bytes(self.contract),
msg=self.msg_encrypted,
sent_funds=self.sent_funds.to_proto(),
Expand Down
6 changes: 6 additions & 0 deletions secret_sdk/protobuf/amino/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
85 changes: 85 additions & 0 deletions secret_sdk/protobuf/cosmos/app/runtime/v1alpha1/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading