acp-plugin-gamesdk 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/PKG-INFO +1 -1
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/acp_plugin_gamesdk/acp_client.py +12 -12
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/acp_plugin_gamesdk/acp_plugin.py +8 -7
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/acp_plugin_gamesdk/acp_token.py +11 -15
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/pyproject.toml +1 -1
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/README.md +0 -0
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/acp_plugin_gamesdk/acp_token_abi.py +0 -0
- {acp_plugin_gamesdk-0.1.1 → acp_plugin_gamesdk-0.1.2}/acp_plugin_gamesdk/interface.py +0 -0
@@ -2,20 +2,18 @@ from datetime import datetime, timedelta
|
|
2
2
|
from typing import List, Optional
|
3
3
|
from web3 import Web3
|
4
4
|
import requests
|
5
|
-
import
|
6
|
-
import
|
7
|
-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../")))
|
8
|
-
from .interface import AcpAgent, AcpJobPhases, AcpState
|
9
|
-
from .acp_token import AcpToken, MemoType
|
5
|
+
from acp_plugin_gamesdk.interface import AcpAgent, AcpJobPhases, AcpState
|
6
|
+
from acp_plugin_gamesdk.acp_token import AcpToken, MemoType
|
10
7
|
import time
|
11
8
|
|
12
9
|
|
13
10
|
class AcpClient:
|
14
|
-
def __init__(self, api_key: str, acp_token: AcpToken):
|
11
|
+
def __init__(self, api_key: str, acp_token: AcpToken, acp_base_url: Optional[str] = None):
|
15
12
|
self.base_url = "https://sdk-dev.game.virtuals.io/acp"
|
16
13
|
self.api_key = api_key
|
17
14
|
self.acp_token = acp_token
|
18
15
|
self.web3 = Web3()
|
16
|
+
self.acp_base_url = acp_base_url if acp_base_url else "https://acpx-staging.virtuals.io/api"
|
19
17
|
|
20
18
|
@property
|
21
19
|
def agent_wallet_address(self) -> str:
|
@@ -29,16 +27,18 @@ class AcpClient:
|
|
29
27
|
return response.json()
|
30
28
|
|
31
29
|
def browse_agents(self, cluster: Optional[str] = None, query: Optional[str] = None) -> List[AcpAgent]:
|
32
|
-
url = "
|
30
|
+
url = f"{self.acp_base_url}/agents"
|
33
31
|
|
34
|
-
|
32
|
+
# Build URL with query parameters
|
35
33
|
if query:
|
36
|
-
|
34
|
+
url += f"?search={requests.utils.quote(query)}"
|
37
35
|
|
38
36
|
if cluster:
|
39
|
-
|
37
|
+
# Add & if there's already a parameter, otherwise add ?
|
38
|
+
separator = "&" if query else "?"
|
39
|
+
url += f"{separator}filters[cluster]={requests.utils.quote(cluster)}"
|
40
40
|
|
41
|
-
response = requests.get(url
|
41
|
+
response = requests.get(url)
|
42
42
|
|
43
43
|
if response.status_code != 200:
|
44
44
|
raise Exception(f"Failed to browse agents: {response.text}")
|
@@ -74,7 +74,7 @@ class AcpClient:
|
|
74
74
|
time.sleep(retry_delay)
|
75
75
|
for attempt in range(retry_count):
|
76
76
|
try:
|
77
|
-
response = self.acp_token.
|
77
|
+
response = self.acp_token.validate_transaction(tx_result["txHash"])
|
78
78
|
data = response.get("data", {})
|
79
79
|
if not data:
|
80
80
|
raise Exception("Invalid tx_hash!")
|
@@ -5,13 +5,11 @@ from datetime import datetime
|
|
5
5
|
|
6
6
|
from game_sdk.game.agent import WorkerConfig
|
7
7
|
from game_sdk.game.custom_types import Function, FunctionResultStatus
|
8
|
-
from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin
|
9
|
-
|
10
8
|
from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin
|
11
9
|
from twitter_plugin_gamesdk.game_twitter_plugin import GameTwitterPlugin
|
12
|
-
from .acp_client import AcpClient
|
13
|
-
from .acp_token import AcpToken
|
14
|
-
from .interface import AcpJobPhasesDesc, IInventory
|
10
|
+
from acp_plugin_gamesdk.acp_client import AcpClient
|
11
|
+
from acp_plugin_gamesdk.acp_token import AcpToken
|
12
|
+
from acp_plugin_gamesdk.interface import AcpJobPhasesDesc, IInventory
|
15
13
|
|
16
14
|
@dataclass
|
17
15
|
class AcpPluginOptions:
|
@@ -19,12 +17,13 @@ class AcpPluginOptions:
|
|
19
17
|
acp_token_client: AcpToken
|
20
18
|
twitter_plugin: TwitterPlugin | GameTwitterPlugin = None
|
21
19
|
cluster: Optional[str] = None
|
20
|
+
acp_base_url: Optional[str] = None
|
21
|
+
|
22
22
|
|
23
23
|
class AcpPlugin:
|
24
24
|
def __init__(self, options: AcpPluginOptions):
|
25
25
|
print("Initializing AcpPlugin")
|
26
|
-
self.acp_client = AcpClient(options.api_key, options.acp_token_client)
|
27
|
-
|
26
|
+
self.acp_client = AcpClient(options.api_key, options.acp_token_client, options.acp_base_url)
|
28
27
|
self.id = "acp_worker"
|
29
28
|
self.name = "ACP Worker"
|
30
29
|
self.description = """
|
@@ -45,6 +44,8 @@ class AcpPlugin:
|
|
45
44
|
self.cluster = options.cluster
|
46
45
|
self.twitter_plugin = options.twitter_plugin
|
47
46
|
self.produced_inventory: List[IInventory] = []
|
47
|
+
self.acp_base_url = options.acp_base_url
|
48
|
+
|
48
49
|
|
49
50
|
def add_produce_item(self, item: IInventory) -> None:
|
50
51
|
self.produced_inventory.append(item)
|
@@ -4,10 +4,7 @@ from typing import Optional, Tuple, TypedDict
|
|
4
4
|
from datetime import datetime
|
5
5
|
from web3 import Web3
|
6
6
|
from eth_account import Account
|
7
|
-
import
|
8
|
-
import os
|
9
|
-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../")))
|
10
|
-
from .acp_token_abi import ACP_TOKEN_ABI
|
7
|
+
from acp_plugin_gamesdk.acp_token_abi import ACP_TOKEN_ABI
|
11
8
|
import requests
|
12
9
|
from eth_account.messages import encode_defunct
|
13
10
|
import json
|
@@ -48,9 +45,9 @@ class AcpToken:
|
|
48
45
|
wallet_private_key: str,
|
49
46
|
agent_wallet_address: str,
|
50
47
|
network_url: str,
|
48
|
+
acp_base_url: Optional[str] = None,
|
51
49
|
contract_address: str = "0x2422c1c43451Eb69Ff49dfD39c4Dc8C5230fA1e6",
|
52
50
|
virtuals_token_address: str = "0xbfAB80ccc15DF6fb7185f9498d6039317331846a",
|
53
|
-
base_url: str = "https://acpx.virtuals.gg/api"
|
54
51
|
):
|
55
52
|
self.web3 = Web3(Web3.HTTPProvider(network_url))
|
56
53
|
self.account = Account.from_key(wallet_private_key)
|
@@ -88,17 +85,16 @@ class AcpToken:
|
|
88
85
|
"type": "function"
|
89
86
|
}]
|
90
87
|
)
|
91
|
-
self.
|
92
|
-
|
88
|
+
self.acp_base_url = acp_base_url if acp_base_url else "https://acpx-staging.virtuals.io/api"
|
93
89
|
def get_agent_wallet_address(self) -> str:
|
94
90
|
return self.agent_wallet_address
|
95
91
|
|
96
92
|
def get_contract_address(self) -> str:
|
97
93
|
return self.contract_address
|
98
94
|
|
99
|
-
def
|
95
|
+
def validate_transaction(self, hash_value: str) -> object:
|
100
96
|
try:
|
101
|
-
response = requests.post(f"{self.
|
97
|
+
response = requests.post(f"{self.acp_base_url}/acp-agent-wallets/trx-result", json={"userOpHash": hash_value})
|
102
98
|
return response.json()
|
103
99
|
except Exception as error:
|
104
100
|
print(f"Error getting job_id: {error}")
|
@@ -128,7 +124,7 @@ class AcpToken:
|
|
128
124
|
}
|
129
125
|
|
130
126
|
# Submit to custom API
|
131
|
-
api_url = f"{self.
|
127
|
+
api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
|
132
128
|
response = requests.post(api_url, json=payload)
|
133
129
|
|
134
130
|
# Return transaction hash or response ID
|
@@ -152,7 +148,7 @@ class AcpToken:
|
|
152
148
|
"signature": signature
|
153
149
|
}
|
154
150
|
|
155
|
-
api_url = f"{self.
|
151
|
+
api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
|
156
152
|
response = requests.post(api_url, json=payload)
|
157
153
|
|
158
154
|
if (response.status_code != 200):
|
@@ -185,7 +181,7 @@ class AcpToken:
|
|
185
181
|
"signature": signature
|
186
182
|
}
|
187
183
|
|
188
|
-
api_url = f"{self.
|
184
|
+
api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
|
189
185
|
response = requests.post(api_url, json=payload)
|
190
186
|
|
191
187
|
if (response.status_code != 200):
|
@@ -240,13 +236,13 @@ class AcpToken:
|
|
240
236
|
"signature": signature
|
241
237
|
}
|
242
238
|
|
243
|
-
api_url = f"{self.
|
239
|
+
api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
|
244
240
|
response = requests.post(api_url, json=payload)
|
245
241
|
|
246
242
|
if (response.status_code != 200):
|
247
243
|
raise Exception("Failed to sign memo")
|
248
244
|
|
249
|
-
return response.json()
|
245
|
+
return response.json()
|
250
246
|
|
251
247
|
except Exception as error:
|
252
248
|
print(f"Error signing memo: {error}")
|
@@ -268,7 +264,7 @@ class AcpToken:
|
|
268
264
|
"signature": signature
|
269
265
|
}
|
270
266
|
|
271
|
-
api_url = f"{self.
|
267
|
+
api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
|
272
268
|
response = requests.post(api_url, json=payload)
|
273
269
|
|
274
270
|
if (response.status_code != 200):
|
File without changes
|
File without changes
|
File without changes
|