Skip to content

Commit

Permalink
bugfix variable assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
achamely authored and andrewrothman committed Jul 19, 2017
1 parent bf71cde commit 802404e
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 358 deletions.
52 changes: 10 additions & 42 deletions api/blockchain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
from config import BTAPIKEY
from rpcclient import gettxout
from cacher import *
import config

BLOCKCHAININFO_API_URL = "https://blockchain.info/"
BLOCKR_API_URL = "http://btc.blockr.io/api/v1"
BLOCKTRAIL_API_URL = "https://api.blocktrail.com/v1/btc/"
BLOCKCYPHER_API_URL = "https://api.blockcypher.com/v1/btc/main/"
BITGO_API_URL = "https://www.bitgo.com/api/v1/"
BLOCKONOMICS_API_URL = "https://www.blockonomics.co/api"

# note: "blockchain.info" does not support testnet
# note: "blockonomics" does not appear to support testnet
TESTNET_BLOCKR_API_URL = "http://tbtc.blockr.io/api/v1"
TESTNET_BLOCKTRAIL_API_URL = "https://api.blocktrail.com/v1/tbtc/"
TESTNET_BLOCKCYPHER_API_URL = "https://api.blockcypher.com/v1/btc/test3/"
TESTNET_BITGO_API_URL = "https://test.bitgo.com/api/v1/"

try:
expTime=config.BTCBAL_CACHE
Expand All @@ -30,8 +15,7 @@ def bc_getutxo(address, ramount, page=1, retval=None, avail=0):
if retval==None:
retval=[]
try:
apiUrl = BLOCKTRAIL_API_URL if not config.TESTNET else TESTNET_BLOCKTRAIL_API_URL
r = requests.get(apiUrlr + '/address/'+address+'/unspent-outputs?api_key='+str(BTAPIKEY)+'&limit=200&page='+str(page))
r = requests.get('https://api.blocktrail.com/v1/btc/address/'+address+'/unspent-outputs?api_key='+str(BTAPIKEY)+'&limit=200&page='+str(page))
if r.status_code == 200:
response = r.json()
unspents = response['data']
Expand All @@ -56,8 +40,7 @@ def bc_getutxo(address, ramount, page=1, retval=None, avail=0):

def bc_getutxo_blockcypher(address, ramount):
try:
apiUrl = BLOCKCYPHER_API_URL if not config.TESTNET else TESTNET_BLOCKCYPHER_API_URL
r = requests.get(apiUrl + '/addrs/'+address+'?unspentOnly=true')
r = requests.get('https://api.blockcypher.com/v1/btc/main/addrs/'+address+'?unspentOnly=true')

if r.status_code == 200:
unspents = r.json()['txrefs']
Expand All @@ -82,8 +65,7 @@ def bc_getutxo_blockcypher(address, ramount):

def bc_getutxo_blockr(address, ramount):
try:
apiUrl = BLOCKR_API_URL if not config.TESTNET else TESTNET_BLOCKR_API_URL
r = requests.get(apiUrl + '/address/unspent/'+address+'?unconfirmed=1')
r = requests.get('http://btc.blockr.io/api/v1/address/unspent/'+address+'?unconfirmed=1')

if r.status_code == 200:
#Process and format response from blockr.io
Expand All @@ -110,12 +92,8 @@ def bc_getutxo_blockr(address, ramount):


def bc_getpubkey(address):
# note: only supports mainnet
try:
if config.TESTNET:
return "error: tried using blockchain.info api with testnet enabled"

r = requests.get(BLOCKCHAININFO_API_URL + '/q/pubkeyaddr/'+address)
r = requests.get('https://blockchain.info/q/pubkeyaddr/'+address)

if r.status_code == 200:
return str(r.text)
Expand All @@ -139,8 +117,7 @@ def bc_getbalance(address):

def bc_getbalance_bitgo(address):
try:
apiUrl = BITGO_API_URL if not config.TESTNET else TESTNET_BITGO_API_URL
r= requests.get(apiUrl + '/address/'+address)
r= requests.get('https://www.bitgo.com/api/v1/address/'+address)
if r.status_code == 200:
balance = int(r.json()['balance'])
return {"bal":balance , "error": None}
Expand All @@ -151,8 +128,7 @@ def bc_getbalance_bitgo(address):

def bc_getbalance_blockcypher(address):
try:
apiUrl = BLOCKCYPHER_API_URL if not config.TESTNET else TESTNET_BLOCKCYPHER_API_URL
r= requests.get(apiUrl + '/addrs/'+address+'/balance')
r= requests.get('https://api.blockcypher.com/v1/btc/main/addrs/'+address+'/balance')
if r.status_code == 200:
balance = int(r.json()['balance'])
return {"bal":balance , "error": None}
Expand All @@ -163,8 +139,7 @@ def bc_getbalance_blockcypher(address):

def bc_getbalance_blockr(address):
try:
apiUrl = BLOCKR_API_URL if not config.TESTNET else TESTNET_BLOCKR_API_URL
r= requests.get(apiUrl + '/address/balance/'+address)
r= requests.get('http://btc.blockr.io/api/v1/address/balance/'+address)
if r.status_code == 200:
balance = int(r.json()['data']['balance']*1e8)
return {"bal":balance , "error": None}
Expand Down Expand Up @@ -247,10 +222,7 @@ def bc_getbulkbalance_blockonomics(addresses):
formatted=formatted+" "+address

try:
if config.TESTNET:
return "error: tried using blockonomics api with testnet enabled"

r = requests.post(apiUrl + '/balance',json.dumps({"addr":formatted}))
r = requests.post('https://www.blockonomics.co/api/balance',json.dumps({"addr":formatted}))
if r.status_code == 200:
balances = r.json()['response']
retval = {}
Expand All @@ -271,8 +243,7 @@ def bc_getbulkbalance_blockr(addresses):
formatted=formatted+","+address

try:
apiUrl = BLOCKR_API_URL if not config.TESTNET else TESTNET_BLOCKR_API_URL
r= requests.get(apiUrl + '/address/balance/'+formatted)
r= requests.get('http://btc.blockr.io/api/v1/address/balance/'+formatted)
if r.status_code == 200:
balances = r.json()['data']
retval = {}
Expand All @@ -292,10 +263,7 @@ def bc_getbulkbalance_blockchain(addresses):
else:
formatted=formatted+"|"+address
try:
if config.TESTNET:
return "error: tried using blockchain.info api with testnet enabled"

r= requests.get(BLOCKCHAININFO_API_URL + '/balance?active='+formatted)
r= requests.get('https://blockchain.info/balance?active='+formatted)
if r.status_code == 200:
balances = r.json()
retval = {}
Expand Down
37 changes: 0 additions & 37 deletions api/config.py

This file was deleted.

3 changes: 0 additions & 3 deletions api/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ REDIS_DB=0
#Use if you want custom address namespace (multiple servers on same box)
#Must prefix custom name with : example ":stage"
REDIS_ADDRSPACE=""

#How long, in seconds, to cache BTC balance info for new addresses, Default 10min (600)
BTCBAL_CACHE=600


TESTNET = False
3 changes: 1 addition & 2 deletions api/rpcclient.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import requests, getpass
import time, json
import config

class RPCHost():
def __init__(self):
USER=getpass.getuser()
self._session = requests.Session()
try:
with open('/home/'+USER+'/.bitcoin/bitcoin.conf') as fp:
RPCPORT= "8332"
RPCPORT="8332"
RPCHOST="localhost"
RPCSSL=False
for line in fp:
Expand Down
16 changes: 8 additions & 8 deletions api/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from blockchain_utils import *
from msc_apps import *
import random
import traceback

def send_form_response(response_dict):
expected_fields=['from_address', 'to_address', 'amount', 'currency', 'fee']
Expand All @@ -19,8 +18,8 @@ def send_form_response(response_dict):
if len(response_dict[field]) != 1:
info('Multiple values for field '+field)
return (None, 'Multiple values for field '+field)

if 'testnet' in response_dict and ( response_dict['testnet'][0] in ['true', 'True'] ):
if 'testnet' in response_dict and ( response_dict['testnet'] in ['true', 'True'] ):
testnet =True
magicbyte = 111
else:
Expand All @@ -33,6 +32,8 @@ def send_form_response(response_dict):
else:
response_status='invalid pubkey'
pubkey=None

print response_dict

from_addr=response_dict['from_address'][0]
if not is_valid_bitcoin_address_or_pubkey(from_addr):
Expand Down Expand Up @@ -102,7 +103,6 @@ def send_form_response(response_dict):
return (response, None)
except Exception as e:
print "error creating unsigned tx", e
traceback.print_exc()
return (None, str(e))


Expand Down Expand Up @@ -251,10 +251,10 @@ def prepare_send_tx_for_signing(from_address, to_address, marker_address, curren
# under dust limit leave all remaining as fees
pass

#tx=mktx(inputs_outputs)
tx=pybitcointools.mktx(ins,outs)
info('inputs_outputs are '+str(ins)+' '+str(outs))
#info('inputs_outputs are '+inputs_outputs)
tx=mktx(inputs_outputs)
#tx.pybitcointools.mktx(ins,outs)
#info('inputs_outputs are '+str(ins)+' '+str(outs))
info('inputs_outputs are '+inputs_outputs)
info('parsed tx is '+str(get_json_tx(tx)))

hash160=bc_address_to_hash_160(from_address).encode('hex_codec')
Expand Down
27 changes: 0 additions & 27 deletions www/assets/img/icons/close.svg

This file was deleted.

3 changes: 0 additions & 3 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
<script src="/js/filters/TimeAgo.js"></script>
<script src="/js/filters/BigJS.js"></script>
<script src="/js/directives/Combobox.js"></script>
<script src="/js/directives/VatomIcon.js"></script>
<script src="/js/directives/VatomCard.js"></script>
<script src="/js/factories/AddressModelFactory.js"></script>
<script src="/js/factories/AssetModelFactory.js"></script>
<script src="/js/factories/TransactionModelFactory.js"></script>
Expand Down Expand Up @@ -116,7 +114,6 @@
<script src="/js/CreateWalletController.js"></script>
<script src="/js/cryptUtil.js"></script>
<script src="/js/cryptUtilAsync.js"></script>
<script src="/js/vatomic-sdk.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
21 changes: 7 additions & 14 deletions www/js/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,13 @@ function Login($injector, $scope, $http, $location, $modalInstance, $q, Account,
});
} else {

Account.login(login.uuid, login.password, login.mfatoken).then(function (wallet) {
// Set app ID
Vatomic.init({
appID: "87b4a201-054c-484c-b206-02742ba9ae87",
serverAddress: "https://api.vatomic.net",
websocketAddress: "wss://websocket.api.vatomic.net"
});

$modalInstance.close()
$location.path('/wallet');
$idle.watch();
}, function (error) {
$scope.loginInProgress = false;
angular.extend($scope, error);
Account.login(login.uuid,login.password,login.mfatoken).then(function(wallet){
$modalInstance.close()
$location.path('/wallet');
$idle.watch();
},function(error){
$scope.loginInProgress=false;
angular.extend($scope,error);
})
}
};
Expand Down
56 changes: 4 additions & 52 deletions www/js/controllers/wallet/OverviewController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module("omniControllers")
.controller("WalletOverviewController", ["$scope","$location","Wallet","ModalManager","$filter", "$http",
function WalletOverviewController($scope,$location,Wallet,ModalManager,$filter, $http){
.controller("WalletOverviewController", ["$scope","$location","Wallet","ModalManager","$filter",
function WalletOverviewController($scope,$location,Wallet,ModalManager,$filter){
$scope.uuid = $scope.account.uuid;
$scope.loginLink = $location.protocol() + "://" + $location.host() + "/login/" + $scope.uuid;
//console.log(Wallet.addresses);
Expand Down Expand Up @@ -49,31 +49,10 @@ angular.module("omniControllers")
ModalManager.openImportWalletModal();
}

function refresh() {
function refresh(){
$scope.total = 0;

const objectAssets = Wallet.assets.filter(asset => asset.url.indexOf("vatomic") !== -1);

Promise.all(objectAssets.map((objectAsset, i) => {
return $http({ method: "GET", url: objectAsset.url })
.then(res => res.data)
.then(objectDef => ({ objectDef, name: objectAsset.name, quantity: Number.parseInt(objectAsset.totaltokens), url: objectAsset.url, propertyid: objectAsset.propertyid }));
}))
.then(resolvedObjects => {
return resolvedObjects
.map(object => {
return new Array(/*Number.parseInt(object.quantity)*/ 1).fill(0).map(() => Object.assign({}, object));
})
.reduce((prev, curr) => prev.concat(curr), []);
})
.then(inventory => {
if ($scope.inventory === undefined || $scope.inventory.length !== inventory.length) {
$scope.inventory = inventory;
$scope.$apply();
}
});

Wallet.assets.forEach(function (asset) {
Wallet.assets.forEach(function(asset) {
$scope.total += parseFloat(asset.value);
});

Expand All @@ -93,31 +72,4 @@ angular.module("omniControllers")
})

refresh();

$scope.startVatomIconTouch = function (object, event) {
$scope.originalMoveLocation = { x: event.clientX, y: event.clientY };
$scope.shouldOpenVatom = true;
};

$scope.endVatomIconTouch = function (object, event) {
if ($scope.shouldOpenVatom) {
$scope.isModalOpen = true;
$scope.selectedObject = object;
}
};

$scope.panVatomIconTouch = function (object, event) {
const MAX_CLICK_DIST = 5;

if ((Math.abs($scope.originalMoveLocation.x - event.clientX) > MAX_CLICK_DIST || Math.abs($scope.originalMoveLocation.y - event.clientY) > MAX_CLICK_DIST) && $scope.shouldOpenVatom) {
$scope.shouldOpenVatom = false;
}
};

$scope.closeVatomCard = function () {
$scope.isModalOpen = false;
$scope.selectedObject = undefined;
};

$scope.isModalOpen = false;
}]);
Loading

0 comments on commit 802404e

Please sign in to comment.