Skip to content

Commit a59e24f

Browse files
authored
Merge pull request #29 from helloissariel/fix/api-call
[Neo]Fix api call
2 parents e7d3a02 + 5a4c9c7 commit a59e24f

15 files changed

+892
-808
lines changed

spoon_toolkits/__init__.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
GetTotalSentAndReceivedTool,
5050
GetRawTransactionByAddressTool,
5151
GetTransferByAddressTool,
52-
GetNep11OwnedByAddressTool,
52+
GetNep11ByAddressAndHashTool,
5353

5454
# Asset tools (5)
5555
GetAssetCountTool,
@@ -66,13 +66,12 @@
6666
GetRecentBlocksInfoTool,
6767
GetBlockRewardByHashTool,
6868

69-
# Contract tools (6)
69+
# Contract tools (5)
7070
GetContractCountTool,
7171
GetContractByHashTool,
7272
GetContractListByNameTool,
7373
GetVerifiedContractByContractHashTool,
7474
GetVerifiedContractTool,
75-
GetSourceCodeByContractHashTool,
7675

7776
# Transaction tools (8)
7877
GetTransactionCountTool,
@@ -95,9 +94,8 @@
9594
GetVotesByCandidateAddressTool,
9695
GetTotalVotesTool,
9796

98-
# NEP tools (12)
97+
# NEP tools (11)
9998
GetNep11BalanceTool,
100-
GetNep11OwnedByAddressTool,
10199
GetNep11ByAddressAndHashTool,
102100
GetNep11TransferByAddressTool,
103101
GetNep11TransferByBlockHeightTool,
@@ -110,28 +108,17 @@
110108
GetNep17TransferCountByAddressTool,
111109

112110
# Smart Contract Call tools (3)
113-
InvokeContractTool,
114-
TestInvokeContractTool,
115-
GetContractStateTool,
111+
GetScCallByContractHashTool,
112+
GetScCallByContractHashAddressTool,
113+
GetScCallByTransactionHashTool,
116114

117115
# Application Log and State tools (2)
118116
GetApplicationLogTool,
119117
GetApplicationStateTool,
120118

121-
# Statistics and Monitoring tools (4)
122-
GetNetworkStatisticsTool,
123-
GetTransactionStatisticsTool,
124-
GetAddressStatisticsTool,
125-
GetContractStatisticsTool,
126-
127119
# Governance tools (1)
128120
GetCommitteeInfoTool,
129121

130-
# Utility tools (3)
131-
ValidateAddressTool,
132-
ConvertAddressTool,
133-
GetNetworkInfoTool,
134-
135122
# Provider
136123
NeoProvider,
137124
get_provider,

spoon_toolkits/crypto/neo/__init__.py

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
GetContractListByNameTool,
3939
GetVerifiedContractByContractHashTool,
4040
GetVerifiedContractTool,
41-
GetSourceCodeByContractHashTool,
4241
)
4342

4443
# Transaction tools
@@ -69,7 +68,6 @@
6968
# NEP tools
7069
from .nep_tools import (
7170
GetNep11BalanceTool,
72-
GetNep11OwnedByAddressTool,
7371
GetNep11ByAddressAndHashTool,
7472
GetNep11TransferByAddressTool,
7573
GetNep11TransferByBlockHeightTool,
@@ -84,9 +82,9 @@
8482

8583
# Smart Contract Call tools
8684
from .sc_call_tools import (
87-
InvokeContractTool,
88-
TestInvokeContractTool,
89-
GetContractStateTool,
85+
GetScCallByContractHashTool,
86+
GetScCallByContractHashAddressTool,
87+
GetScCallByTransactionHashTool,
9088
)
9189

9290
# Application Log and State tools
@@ -95,26 +93,11 @@
9593
GetApplicationStateTool,
9694
)
9795

98-
# Statistics and Monitoring tools
99-
from .statistics_tools import (
100-
GetNetworkStatisticsTool,
101-
GetTransactionStatisticsTool,
102-
GetAddressStatisticsTool,
103-
GetContractStatisticsTool,
104-
)
105-
10696
# Governance tools
10797
from .governance_tools import (
10898
GetCommitteeInfoTool,
10999
)
110100

111-
# Utility tools
112-
from .utility_tools import (
113-
ValidateAddressTool,
114-
ConvertAddressTool,
115-
GetNetworkInfoTool,
116-
)
117-
118101
# Provider
119102
from .neo_provider import NeoProvider
120103
from .base import get_provider
@@ -145,13 +128,12 @@
145128
"GetRecentBlocksInfoTool",
146129
"GetBlockRewardByHashTool",
147130

148-
# Contract tools (6)
131+
# Contract tools (5)
149132
"GetContractCountTool",
150133
"GetContractByHashTool",
151134
"GetContractListByNameTool",
152135
"GetVerifiedContractByContractHashTool",
153136
"GetVerifiedContractTool",
154-
"GetSourceCodeByContractHashTool",
155137

156138
# Transaction tools (8)
157139
"GetTransactionCountTool",
@@ -174,9 +156,8 @@
174156
"GetVotesByCandidateAddressTool",
175157
"GetTotalVotesTool",
176158

177-
# NEP tools (12)
159+
# NEP tools (11)
178160
"GetNep11BalanceTool",
179-
"GetNep11OwnedByAddressTool",
180161
"GetNep11ByAddressAndHashTool",
181162
"GetNep11TransferByAddressTool",
182163
"GetNep11TransferByBlockHeightTool",
@@ -189,28 +170,17 @@
189170
"GetNep17TransferCountByAddressTool",
190171

191172
# Smart Contract Call tools (3)
192-
"InvokeContractTool",
193-
"TestInvokeContractTool",
194-
"GetContractStateTool",
173+
"GetScCallByContractHashTool",
174+
"GetScCallByContractHashAddressTool",
175+
"GetScCallByTransactionHashTool",
195176

196177
# Application Log and State tools (2)
197178
"GetApplicationLogTool",
198179
"GetApplicationStateTool",
199-
200-
# Statistics and Monitoring tools (4)
201-
"GetNetworkStatisticsTool",
202-
"GetTransactionStatisticsTool",
203-
"GetAddressStatisticsTool",
204-
"GetContractStatisticsTool",
205-
180+
206181
# Governance tools (1)
207182
"GetCommitteeInfoTool",
208183

209-
# Utility tools (3)
210-
"ValidateAddressTool",
211-
"ConvertAddressTool",
212-
"GetNetworkInfoTool",
213-
214184
# Provider
215185
"NeoProvider",
216186
"get_provider",

spoon_toolkits/crypto/neo/address_tools.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class GetAddressCountTool(BaseTool):
2121

2222
async def execute(self, network: str = "testnet") -> ToolResult:
2323
try:
24-
provider = get_provider(network)
25-
result = await provider.get_address_count()
26-
return ToolResult(output=f"Address count: {result}")
24+
async with get_provider(network) as provider:
25+
result = await provider.get_address_count()
26+
return ToolResult(output=f"Address count: {result}")
2727
except Exception as e:
2828
return ToolResult(error=str(e))
2929

@@ -49,9 +49,9 @@ class GetAddressInfoTool(BaseTool):
4949

5050
async def execute(self, address: str, network: str = "testnet") -> ToolResult:
5151
try:
52-
provider = get_provider(network)
53-
result = await provider.get_address_info(address)
54-
return ToolResult(output=f"Address info: {result}")
52+
async with get_provider(network) as provider:
53+
result = await provider.get_address_info(address)
54+
return ToolResult(output=f"Address info: {result}")
5555
except Exception as e:
5656
return ToolResult(error=str(e))
5757

@@ -81,11 +81,11 @@ class GetActiveAddressesTool(BaseTool):
8181

8282
async def execute(self, days: int, network: str = "testnet") -> ToolResult:
8383
try:
84-
provider = get_provider(network)
85-
result = await provider.get_active_addresses(days)
86-
if not result:
87-
return ToolResult(output="Active addresses data not available with current neo-mamba implementation")
88-
return ToolResult(output=f"Active addresses: {result}")
84+
async with get_provider(network) as provider:
85+
result = await provider.get_active_addresses(days)
86+
if not result:
87+
return ToolResult(output="Active addresses data not available with current neo-mamba implementation")
88+
return ToolResult(output=f"Active addresses: {result}")
8989
except Exception as e:
9090
return ToolResult(error=str(e))
9191

@@ -112,26 +112,26 @@ class GetTagByAddressesTool(BaseTool):
112112
"required": ["addresses"]
113113
}
114114

115-
async def execute(self, addresses: str, network: str = "testnet") -> ToolResult:
116-
try:
117-
provider = get_provider(network)
118-
# Convert string to list if needed
119-
if isinstance(addresses, str):
120-
addresses = [addr.strip() for addr in addresses.split(",")]
121-
122-
# Note: neo-mamba doesn't have a direct GetTagByAddresses method
123-
# For now, we'll get basic balance information for each address
124-
results = {}
125-
for addr in addresses:
126-
try:
127-
addr_info = await provider.get_address_info(addr)
128-
results[addr] = addr_info
129-
except Exception as e:
130-
results[addr] = {"error": str(e)}
131-
132-
return ToolResult(output=f"Address information: {results}")
133-
except Exception as e:
134-
return ToolResult(error=str(e))
115+
async def execute(self, addresses: str, network: str = "testnet") -> ToolResult:
116+
try:
117+
async with get_provider(network) as provider:
118+
# Convert string to list if needed
119+
if isinstance(addresses, str):
120+
addresses = [addr.strip() for addr in addresses.split(",")]
121+
122+
# Note: neo-mamba doesn't have a direct GetTagByAddresses method
123+
# For now, we'll get basic balance information for each address
124+
results = {}
125+
for addr in addresses:
126+
try:
127+
addr_info = await provider.get_address_info(addr)
128+
results[addr] = addr_info
129+
except Exception as e:
130+
results[addr] = {"error": str(e)}
131+
132+
return ToolResult(output=f"Address information: {results}")
133+
except Exception as e:
134+
return ToolResult(error=str(e))
135135

136136
class GetTotalSentAndReceivedTool(BaseTool):
137137
name: str = "get_total_sent_and_received"
@@ -159,26 +159,26 @@ class GetTotalSentAndReceivedTool(BaseTool):
159159

160160
async def execute(self, contract_hash: str, address: str, network: str = "testnet") -> ToolResult:
161161
try:
162-
provider = get_provider(network)
163-
validated_address = provider._validate_address(address)
162+
async with get_provider(network) as provider:
163+
validated_address = await provider._validate_address(address)
164164

165-
# Note: neo-mamba doesn't have GetTotalSentAndReceived method
166-
# We'll use get_nep17_transfers to get transfer history
167-
transfers = await provider.rpc_client.get_nep17_transfers(validated_address)
165+
# Note: neo-mamba doesn't have GetTotalSentAndReceived method
166+
# We'll use get_nep17_transfers to get transfer history
167+
transfers = await provider.rpc_client.get_nep17_transfers(validated_address)
168168

169169
# Calculate totals from transfer history
170170
sent_total = 0
171171
received_total = 0
172172

173-
if transfers and 'sent' in transfers:
174-
for transfer in transfers['sent']:
175-
if transfer.get('contract') == contract_hash:
176-
sent_total += int(transfer.get('amount', 0))
173+
if transfers and hasattr(transfers, 'sent') and transfers.sent:
174+
for transfer in transfers.sent:
175+
if hasattr(transfer, 'contract') and str(transfer.contract) == contract_hash:
176+
sent_total += int(getattr(transfer, 'amount', 0))
177177

178-
if transfers and 'received' in transfers:
179-
for transfer in transfers['received']:
180-
if transfer.get('contract') == contract_hash:
181-
received_total += int(transfer.get('amount', 0))
178+
if transfers and hasattr(transfers, 'received') and transfers.received:
179+
for transfer in transfers.received:
180+
if hasattr(transfer, 'contract') and str(transfer.contract) == contract_hash:
181+
received_total += int(getattr(transfer, 'amount', 0))
182182

183183
result = {
184184
"address": address,
@@ -213,12 +213,12 @@ class GetRawTransactionByAddressTool(BaseTool):
213213

214214
async def execute(self, address: str, network: str = "testnet") -> ToolResult:
215215
try:
216-
provider = get_provider(network)
217-
validated_address = provider._validate_address(address)
218-
# Note: neo-mamba doesn't have GetRawTransactionByAddress method
219-
# We'll use get_nep17_transfers as an alternative
220-
transfers = await provider.rpc_client.get_nep17_transfers(validated_address)
221-
return ToolResult(output=f"Transfer data: {transfers}")
216+
async with get_provider(network) as provider:
217+
validated_address = await provider._validate_address(address)
218+
# Note: neo-mamba doesn't have GetRawTransactionByAddress method
219+
# We'll use get_nep17_transfers as an alternative
220+
transfers = await provider.rpc_client.get_nep17_transfers(validated_address)
221+
return ToolResult(output=f"Transfer data: {transfers}")
222222
except Exception as e:
223223
return ToolResult(error=str(e))
224224

@@ -244,11 +244,11 @@ class GetTransferByAddressTool(BaseTool):
244244

245245
async def execute(self, address: str, network: str = "testnet") -> ToolResult:
246246
try:
247-
provider = get_provider(network)
248-
validated_address = provider._validate_address(address)
249-
# Use neo-mamba's get_nep17_transfers method
250-
transfers = await provider.rpc_client.get_nep17_transfers(validated_address)
251-
return ToolResult(output=f"Transfer data: {transfers}")
247+
async with get_provider(network) as provider:
248+
validated_address = await provider._validate_address(address)
249+
# Use neo-mamba's get_nep17_transfers method
250+
transfers = await provider.rpc_client.get_nep17_transfers(validated_address)
251+
return ToolResult(output=f"Transfer data: {transfers}")
252252
except Exception as e:
253253
return ToolResult(error=str(e))
254254

@@ -274,10 +274,10 @@ class GetNep11OwnedByAddressTool(BaseTool):
274274

275275
async def execute(self, address: str, network: str = "testnet") -> ToolResult:
276276
try:
277-
provider = get_provider(network)
278-
validated_address = provider._validate_address(address)
279-
# Note: neo-mamba doesn't have a direct NEP-11 method
280-
# NEP-11 tokens would need to be queried through contract interactions
281-
return ToolResult(output="NEP-11 token ownership query not available with current neo-mamba implementation")
277+
async with get_provider(network) as provider:
278+
validated_address = await provider._validate_address(address)
279+
# Note: neo-mamba doesn't have a direct NEP-11 method
280+
# NEP-11 tokens would need to be queried through contract interactions
281+
return ToolResult(output="NEP-11 token ownership query not available with current neo-mamba implementation")
282282
except Exception as e:
283-
return ToolResult(error=str(e))
283+
return ToolResult(error=str(e))

0 commit comments

Comments
 (0)