-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoStampBasic
59 lines (49 loc) · 1.9 KB
/
AutoStampBasic
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
import os
import base64
import json
import requests
from requests.auth import HTTPBasicAuth
import sys
# Set the URL, headers, and authentication for the API request
url = "https://api.counterparty.io"
headers = {'content-type': 'application/json'}
auth = HTTPBasicAuth('user', '1234')
# Prompt the user for the transfer address
transfer_address = input("Enter the transfer address for the assets: ")
# 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": "mpWyX9b5fczkrNMKjgmLuCgY5eAGc5P5mb",
"asset": asset_name,
"quantity": 1,
"divisible": False,
"description": "Stamp: " + base64_img,
"lock": True,
"transfer_destination": transfer_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)