testing-tools-plugin/testing.py

95 lines
2.4 KiB
Python
Raw Normal View History

2025-01-31 11:28:13 +11:00
import json
import account
import requests
# Plugin Data
info = {
"name": "Testing tools",
"description": "Testing tools<br>Might not be useful for you",
2025-01-31 11:28:13 +11:00
"version": "1.0",
"author": "Nathan.Woodburn/"
}
# Functions
functions = {
"generate":{
"name": "Generate blocks",
"type": "default",
"description": "Generate blocks to your wallet",
"params": {
"numblocks": {
"name":"Number of blocks to generate",
"type":"number"
},
"address": {
"name":"Address to generate to",
"type":"text"
}
},
"returns": {
"status":
{
"name": "Status of the function",
"type": "text"
}
}
2025-02-01 16:52:08 +11:00
},
"txCount":{
"name": "Count TXs",
"type": "default",
"description": "Get the number of TXs",
"params": {},
"returns": {
"txs":
{
"name": "Transactions",
"type": "text"
}
}
2025-02-04 18:09:28 +11:00
},
"nodeInfo": {
"name": "Node info",
"type": "default",
"description": "Get node info",
"params": {},
"returns": {
"info":
{
"name": "Node info",
"type": "text"
}
}
2025-01-31 11:28:13 +11:00
}
}
def generate(params, authentication):
# hsd-cli rpc generatetoaddress $numblocks $address
number = params["numblocks"]
address = params["address"]
if number == "" or int(number) < 1:
number = 1
if address == "":
wallet = authentication.split(":")[0]
address = account.getAddress(wallet)
print(f"Generating {number} blocks to {address}")
blocks = account.hsd.rpc_generateToAddress(address,number)
return {"status": f"Successfully generated {number} blocks to {address}"}
2025-02-01 16:52:08 +11:00
def txCount(params, authentication):
wallet = authentication.split(":")[0]
txCount = 0
page = 1
while True:
txs = account.getTransactions(wallet,page)
if len(txs) == 0:
break
txCount += len(txs)
page += 1
return {"txs": f'Total TXs: {txCount}'}
2025-02-04 18:09:28 +11:00
def nodeInfo(params, authentication):
info = account.hsd.rpc_getInfo()
return {"info": f"Node info: {json.dumps(info)}"}