Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
new contract
Browse files Browse the repository at this point in the history
  • Loading branch information
bashalex committed Apr 9, 2016
1 parent 176f823 commit 8701394
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
1 change: 0 additions & 1 deletion API.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def getInfo(self, from_address, to_address, data):
response = self.api_request("eth_call", [{"from": from_address,
"to": to_address,
"data": data}, "latest"])
print(response)
return APIResponse({"data": response.response_dict["result"]})

#tested on samples
Expand Down
40 changes: 19 additions & 21 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from addresses import BASE_ADDRESS, CONTRACT_ADDRESS
from datetime import datetime
import binascii
import hashlib

app = Flask(__name__)
api = API()
Expand All @@ -15,26 +16,24 @@ def info():

@app.route("/contract_get_sale/")
def get_sale():
try:
id = int(request.args.get('id', -1))
except ValueError:
return jsonify({"status": "OK", "tx_id": "None", "amount": "None", "date": "None"})
if id < 0:
return jsonify({"status": "OK", "tx_id": "None", "amount": "None", "date": "None"})
num_of_sales_method = "0x" + api.getMethodId("numberOfSales()")
num_of_sales = api.getInfo(BASE_ADDRESS, CONTRACT_ADDRESS, num_of_sales_method)["data"]
num_of_sales = int(num_of_sales, 0)
print(id, num_of_sales)
if id >= num_of_sales:
return jsonify({"status": "OK", "tx_id": "None", "amount": "None", "date": "None"})
tx_id = call_method("getSaleTxId(uint32)", id)
amount = call_method("getSaleAmount(uint32)", id)
date = call_method("getSaleDate(uint32)", id)
print(tx_id, amount, date)
txid = request.args.get('id', "")
if len(txid) != 64:
return jsonify({"status": "OK",
"amount": "Error",
"date": "length of TxID should be equal to 64 symbols"})
print("txid: " + str(len(txid)))
print(str.encode(txid))
mhash = hashlib.md5(str.encode(txid)).hexdigest().upper()
print(mhash)
method = "0x" + api.getMethodId("getSaleDate(bytes16)") + mhash
response = api.getInfo(BASE_ADDRESS, CONTRACT_ADDRESS, method)["data"]
amount = int("0x" + response[2:66], 0)
date = int("0x" + response[66:], 0)
print(amount)
print(date)
return jsonify({"status": "OK",
"tx_id": tx_id,
"amount": int(amount, 0) / 10**8,
"date": datetime.fromtimestamp(int(date, 0))})
"amount": amount / 10**8,
"date": datetime.fromtimestamp(date)})


def call_method(method, id):
Expand Down Expand Up @@ -69,5 +68,4 @@ def uint_to_bytes_string(number):
return str(binascii.b2a_hex(number_bytes), 'ascii')

if __name__ == "__main__":
app.debug = True
app.run(host="0.0.0.0", port=8000)
app.run(host="0.0.0.0", port=8000)
2 changes: 1 addition & 1 deletion addresses.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BASE_ADDRESS = "d079c22e9c63341bf839a8634e8892c430d724cf"
CONTRACT_ADDRESS = "0xA0929Cca97a25bdb2f74a6FcAf78006Cd9F4AD68"
CONTRACT_ADDRESS = "0x7aFaaCB0a6cBB93aEb301cb956AE71a35542ECc5"
14 changes: 5 additions & 9 deletions static/contract_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body onload="loadInfo()">
<div style="border: ridge; width: 50%; margin:0 auto;">
<div style="border: 2pt ridge #0EB1F2; border-radius: 5pt; width: 50%; margin:0 auto;">
<div class="title">
Total number of sales
</div>
Expand All @@ -21,13 +21,11 @@
<div class="title">Sale information</div>
<form>
Enter the TxID of sale to get detailed information:<br>
<input type="text" id="numberOfSale" value="0">
<input type="button" onclick="get_sale()" value="Get info">
<input type="text" id="numberOfSale" value="">
<input type="button" style="background: #0EB1F2; color: white; border: 1pt solid white; border-radius: 2pt" onclick="get_sale()" value="Get info">
</form>
<div style="padding-left: 10pt">Transaction Id:</div>
<div class="hash">None</div>
<div style="padding-left: 10pt" id="amount">Amount: None</div>
<div style="padding-left: 10pt" id="date">Date: None</div>
<div style="padding-left: 10pt; margin-top: 2pt; margin-bottom: 2pt;" id="amount">Amount: None</div>
<div style="padding-left: 10pt; margin-top: 2pt; margin-bottom: 2pt;" id="date">Date: None</div>
</div>
<script>
function loadInfo() {
Expand All @@ -39,14 +37,12 @@
$("#info").html("Sorry, something went wrong. Try to reload the page.")
}
});
get_sale();
}

function get_sale() {
var numberOfSale = $('#numberOfSale').val();
$.get( "contract_get_sale/?id=" + numberOfSale, function(data) {
if (data.status == "OK") {
$(".hash").html(data.tx_id);
$("#amount").html("Amount: " + data.amount);
$("#date").html("Date: " + data.date);
}
Expand Down
10 changes: 7 additions & 3 deletions static/contract_styles.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
form {
text-align: center;
text-align: center;
margin-bottom: 5pt;
margin-top: 5pt;
}

.title {
height: 16pt;
height: 18pt;
line-height: 18pt;
padding-left: 20pt;
background-color: lightgray;
color: white;
background-color: #0EB1F2;
}

.value {
Expand Down
6 changes: 4 additions & 2 deletions wavesPresale.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from API import API
from addresses import BASE_ADDRESS, CONTRACT_ADDRESS
import binascii
import hashlib
import sys

api = API()
Expand All @@ -11,10 +12,11 @@ def logSale(bitcoin_tx_id, amount, timestamp):
if len(bitcoin_tx_id) != 64:
print('TX Id must contain 64 symbols')
return
definition = "newSale(bytes32,uint256,uint256)"
definition = "newSale(bytes16,uint256,uint256)"
method_id = api.getMethodId(definition)
amount = abs(int(amount * (10 ** 8)))
data = "0x" + method_id + bitcoin_tx_id + uint_to_bytes_string(amount)\
mhash = hashlib.md5(str.encode(bitcoin_tx_id)).hexdigest().upper() + "0" * 32
data = "0x" + method_id + mhash + uint_to_bytes_string(amount)\
+ uint_to_bytes_string(timestamp)
gas_price = hex(api.getGasPrice()["result"])
response = api.send_transaction(BASE_ADDRESS, CONTRACT_ADDRESS,
Expand Down

0 comments on commit 8701394

Please sign in to comment.