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

refactor(API): add a user agent #40

Merged
merged 2 commits into from
Jun 6, 2024
Merged
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
10 changes: 9 additions & 1 deletion ape_safe/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
from datetime import datetime
from functools import reduce
from typing import Dict, Iterator, Optional, Union, cast

from ape.types import AddressType, HexBytes, MessageSignature
from ape.utils.misc import USER_AGENT, get_package_version
from eip712.common import SafeTxV1, SafeTxV2

from ape_safe.client.base import BaseSafeClient
Expand All @@ -25,6 +27,12 @@
)
from ape_safe.utils import get_safe_tx_hash, order_by_signer

APE_SAFE_VERSION = get_package_version(__name__)
APE_SAFE_USER_AGENT = f"Ape-Safe/{APE_SAFE_VERSION} {USER_AGENT}"
# NOTE: Origin must be a string, but can be json that contains url & name fields
ORIGIN = json.dumps(dict(url="https://apeworx.io", name="Ape Safe", ua=APE_SAFE_USER_AGENT))
assert len(ORIGIN) <= 200 # NOTE: Must be less than 200 chars

TRANSACTION_SERVICE_URL = {
# NOTE: If URLs need to be updated, a list of available service URLs can be found at
# https://docs.safe.global/safe-core-api/available-services.
Expand Down Expand Up @@ -118,7 +126,7 @@ def post_transaction(
b"",
)
)
post_dict: Dict = {"signature": signature.hex()}
post_dict: Dict = {"signature": signature.hex(), "origin": ORIGIN}
antazoey marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is valid? I don't see it in the OpenAPI doc whereas I do so "origin" in some of the other parts of the doc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this from safe-eth-py but come to think of it, basically everything else about that package is wrong lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is valid? I don't see it in the OpenAPI doc whereas I do so "origin" in some of the other parts of the doc.

For some reason, only SafeMultisigTransaction has this (optional) field in the swagger


for key, value in tx_data.model_dump(by_alias=True, mode="json").items():
if isinstance(value, HexBytes):
Expand Down
Loading