-
Notifications
You must be signed in to change notification settings - Fork 1
/
MintyStampCostCalulator
71 lines (60 loc) · 2.48 KB
/
MintyStampCostCalulator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import base64
import json
import requests
from requests.auth import HTTPBasicAuth
import sys
# Prompt the user for their RPC information, source wallet address, and destination address
rpc_user = input("Enter your RPC username: ")
rpc_password = input("Enter your RPC password: ")
rpc_port = input("Enter your RPC port: ")
source_address = input("Enter your source wallet address: ")
destination_address = input("Enter the transfer address for the assets: ")
# Set the URL, headers, and authentication for the API request
url = f"http://{rpc_user}:{rpc_password}@localhost:{rpc_port}"
headers = {'content-type': 'application/json'}
auth = HTTPBasicAuth(rpc_user, rpc_password)
# Get the full path to the PNGIN directory
pngin_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "venv", "PNGIN")
# Check if PNGIN directory exists
if not os.path.exists(pngin_dir):
print("PNGIN directory not found.")
sys.exit()
# Get list of PNG files in the PNGIN directory
png_files = [f for f in os.listdir(pngin_dir) if f.endswith('.png')]
if not png_files:
print("No PNG files found in PNGIN directory.")
sys.exit()
# Loop through each .png file in the PNGIN directory and convert it to base64
for file_name in png_files:
with open(os.path.join(pngin_dir, file_name), 'rb') as f:
base64_img = base64.b64encode(f.read()).decode('utf-8')
# Set the asset name to the file name (without the extension)
asset_name = os.path.splitext(file_name)[0]
# Create a payload with the base64-encoded image in the description field
payload = {
"method": "create_issuance",
"params": {
"source": source_address,
"asset": asset_name,
"quantity": 1,
"divisible": False,
"description": "Stamp: " + base64_img,
"lock": True,
"transfer_destination": destination_address,
"reset": False,
"allow_unconfirmed_inputs": True
},
"jsonrpc": "2.0",
"id": 0
}
# Send the API request
response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth)
print("Response for", file_name, ":", response.text)
# Check the satoshi cost and ask user if they want to proceed
satoshi_cost = response.json()['result']['fee']
print(f"Satoshi cost: {satoshi_cost}")
proceed = input("Do you want to proceed with the transaction? (y/n): ")
if proceed.lower() != "y":
print("Transaction canceled.")
sys.exit()