-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
157 lines (143 loc) · 2.92 KB
/
main.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/popup', methods=['POST'])
def popup():
name = request.form['name']
return jsonify({'name': name})
@app.route('/get_message', methods=['POST'])
def get_message():
name = request.form['name']
message = hashWithKeccak(name)
return jsonify({'message': message})
def hashWithKeccak(name):
from web3 import Web3
from web3.middleware import geth_poa_middleware
bsc_testnet_url = 'https://data-seed-prebsc-1-s1.binance.org:8545/'
contract_address = '0xBB222923D7faB47657B61ED697e0F55A97B2dcd4'
contract_abi = [
{
"inputs": [],
"name": "commision",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_toWalletHash",
"type": "bytes32"
}
],
"name": "deposit",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_armyHash",
"type": "bytes32"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
},
{
"inputs": [
{
"internalType": "bool",
"name": "isDeposit",
"type": "bool"
}
],
"name": "getLastBlockDigit",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "addresses",
"type": "address[]"
}
],
"name": "hashAddressList",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "value1",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "value2",
"type": "bytes32"
}
],
"name": "hashValues",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
}
]
web3 = Web3(Web3.HTTPProvider(bsc_testnet_url))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
contract = web3.eth.contract(address=contract_address, abi=contract_abi)
addressAsList = [str(web3.to_checksum_address(name))]
result = contract.functions.hashAddressList(addressAsList).call()
result = bytes32_to_string(result)
return f"To Wallet Hash: {result}"
def bytes32_to_string(bytes32_value):
hex_string = f"0x{str(bytes32_value.hex())}"
return hex_string
if __name__ == '__main__':
app.run(debug=True)