Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,171 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import hashlib
|
| 3 |
-
import qrcode
|
| 4 |
-
from web3 import Web3
|
| 5 |
-
from solcx import compile_standard, install_solc
|
| 6 |
-
import os
|
| 7 |
-
import base64
|
| 8 |
-
from io import BytesIO
|
| 9 |
-
import secrets
|
| 10 |
-
|
| 11 |
-
# Initialize Web3
|
| 12 |
-
w3 = Web3(Web3.HTTPProvider('https://rpc.buildbear.io/electronic-greengoblin-7f41d04d'))
|
| 13 |
-
account = w3.eth.accounts.privateKeyToAccount('0717a51dacfc205a8c7bb5b3752a76c298d8e9caf57ac7c03037800c50265a22')
|
| 14 |
-
w3.eth.accounts.wallet.add(account)
|
| 15 |
-
w3.eth.defaultAccount = account.address
|
| 16 |
-
|
| 17 |
-
# Solidity source code for JBO3Token
|
| 18 |
-
contract_source_code = '''
|
| 19 |
-
pragma solidity ^0.8.0;
|
| 20 |
-
|
| 21 |
-
contract JBO3Token {
|
| 22 |
-
string public name = "JBO3Token";
|
| 23 |
-
string public symbol = "JBO3";
|
| 24 |
-
uint8 public decimals = 18;
|
| 25 |
-
uint256 public totalSupply;
|
| 26 |
-
|
| 27 |
-
address public owner;
|
| 28 |
-
mapping(address => uint256) public balanceOf;
|
| 29 |
-
mapping(address => mapping(address => uint256)) public allowance;
|
| 30 |
-
mapping(bytes32 => bool) public storedHashes;
|
| 31 |
-
|
| 32 |
-
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 33 |
-
event Approval(address indexed owner, address indexed spender, uint256 value);
|
| 34 |
-
event DataHashStored(bytes32 indexed dataHash);
|
| 35 |
-
|
| 36 |
-
modifier onlyOwner() {
|
| 37 |
-
require(msg.sender == owner, "Only the owner can execute this function");
|
| 38 |
-
_;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
constructor(uint256 initialSupply) {
|
| 42 |
-
owner = msg.sender;
|
| 43 |
-
totalSupply = initialSupply * 10 ** uint256(decimals);
|
| 44 |
-
balanceOf[msg.sender] = totalSupply;
|
| 45 |
-
emit Transfer(address(0), msg.sender, totalSupply);
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
function transfer(address _to, uint256 _value) public returns (bool success) {
|
| 49 |
-
require(_to != address(0), "Invalid address");
|
| 50 |
-
require(balanceOf[msg.sender] >= _value, "Insufficient balance");
|
| 51 |
-
balanceOf[msg.sender] -= _value;
|
| 52 |
-
balanceOf[_to] += _value;
|
| 53 |
-
emit Transfer(msg.sender, _to, _value);
|
| 54 |
-
return true;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
function approve(address _spender, uint256 _value) public returns (bool success) {
|
| 58 |
-
allowance[msg.sender][_spender] = _value;
|
| 59 |
-
emit Approval(msg.sender, _spender, _value);
|
| 60 |
-
return true;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
|
| 64 |
-
require(_to != address(0), "Invalid address");
|
| 65 |
-
require(balanceOf[_from] >= _value, "Insufficient balance");
|
| 66 |
-
require(allowance[_from][msg.sender] >= _value, "Allowance exceeded");
|
| 67 |
-
balanceOf[_from] -= _value;
|
| 68 |
-
balanceOf[_to] += _value;
|
| 69 |
-
allowance[_from][msg.sender] -= _value;
|
| 70 |
-
emit Transfer(_from, _to, _value);
|
| 71 |
-
return true;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
function mint(address _to, uint256 _amount) public onlyOwner returns (bool success) {
|
| 75 |
-
totalSupply += _amount * 10 ** uint256(decimals);
|
| 76 |
-
balanceOf[_to] += _amount * 10 ** uint256(decimals);
|
| 77 |
-
emit Transfer(address(0), _to, _amount * 10 ** uint256(decimals));
|
| 78 |
-
return true;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
function storeDataHash(bytes32 dataHash) public onlyOwner returns (bool success) {
|
| 82 |
-
storedHashes[dataHash] = true;
|
| 83 |
-
emit DataHashStored(dataHash);
|
| 84 |
-
return true;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
function verifyDataHash(bytes32 dataHash) public view returns (bool) {
|
| 88 |
-
return storedHashes[dataHash];
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
'''
|
| 92 |
-
|
| 93 |
-
# Install the Solidity compiler
|
| 94 |
-
install_solc('0.8.0')
|
| 95 |
-
|
| 96 |
-
# Compile the contract
|
| 97 |
-
compiled_sol = compile_standard({
|
| 98 |
-
"language": "Solidity",
|
| 99 |
-
"sources": {
|
| 100 |
-
"JBO3Token.sol": {
|
| 101 |
-
"content": contract_source_code
|
| 102 |
-
}
|
| 103 |
-
},
|
| 104 |
-
"settings": {
|
| 105 |
-
"outputSelection": {
|
| 106 |
-
"*": {
|
| 107 |
-
"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]
|
| 108 |
-
}
|
| 109 |
-
}
|
| 110 |
-
}
|
| 111 |
-
})
|
| 112 |
-
|
| 113 |
-
contract_interface = compiled_sol['contracts']['JBO3Token.sol']['JBO3Token']
|
| 114 |
-
|
| 115 |
-
# Deploy the contract
|
| 116 |
-
JBO3 = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['evm']['bytecode']['object'])
|
| 117 |
-
tx_hash = JBO3.constructor(1000000).transact()
|
| 118 |
-
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
|
| 119 |
-
contract_address = tx_receipt.contractAddress
|
| 120 |
-
jbo3_contract = w3.eth.contract(address=contract_address, abi=contract_interface['abi'])
|
| 121 |
-
|
| 122 |
-
def parse_file(file):
|
| 123 |
-
file_content = file.read()
|
| 124 |
-
file_text = file_content.decode('utf-8', errors='ignore')
|
| 125 |
-
file_hash = hashlib.sha3_256(file_text.encode()).hexdigest()
|
| 126 |
-
return file_hash, file_text
|
| 127 |
-
|
| 128 |
-
def generate_wallet():
|
| 129 |
-
private_key = secrets.token_hex(32)
|
| 130 |
-
account = w3.eth.account.privateKeyToAccount(private_key)
|
| 131 |
-
address = account.address
|
| 132 |
-
return private_key, address
|
| 133 |
-
|
| 134 |
-
def mint_tokens(address, amount):
|
| 135 |
-
tx_hash = jbo3_contract.functions.mint(address, amount).transact()
|
| 136 |
-
w3.eth.waitForTransactionReceipt(tx_hash)
|
| 137 |
-
|
| 138 |
-
def create_qr_code(data):
|
| 139 |
-
qr = qrcode.QRCode(version=1, box_size=10, border=5)
|
| 140 |
-
qr.add_data(data)
|
| 141 |
-
qr.make(fit=True)
|
| 142 |
-
img = qr.make_image(fill='black', back_color='white')
|
| 143 |
-
buffered = BytesIO()
|
| 144 |
-
img.save(buffered, format="PNG")
|
| 145 |
-
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 146 |
-
return img_str
|
| 147 |
-
|
| 148 |
-
def process_file(file):
|
| 149 |
-
file_hash, file_text = parse_file(file)
|
| 150 |
-
private_key, address = generate_wallet()
|
| 151 |
-
mint_tokens(address, 1) # 1 JBO3 token for simplicity
|
| 152 |
-
qr_code = create_qr_code(private_key)
|
| 153 |
-
return {
|
| 154 |
-
"File Hash": file_hash,
|
| 155 |
-
"Wallet Address": address,
|
| 156 |
-
"QR Code": qr_code
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
iface = gr.Interface(
|
| 160 |
-
fn=process_file,
|
| 161 |
-
inputs=gr.inputs.File(),
|
| 162 |
-
outputs=[
|
| 163 |
-
gr.outputs.Textbox(label="File Hash"),
|
| 164 |
-
gr.outputs.Textbox(label="Wallet Address"),
|
| 165 |
-
gr.outputs.Image(label="QR Code")
|
| 166 |
-
],
|
| 167 |
-
title="JBO3 Token Generator",
|
| 168 |
-
description="Upload a file to generate a JBO3 token wallet with a value based on the file's content."
|
| 169 |
-
)
|
| 170 |
-
|
| 171 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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