Skip to content

Commit

Permalink
bugfix array use
Browse files Browse the repository at this point in the history
  • Loading branch information
achamely authored and andrewrothman committed Jul 19, 2017
1 parent dde63fc commit bf71cde
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 30 deletions.
52 changes: 42 additions & 10 deletions api/blockchain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
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 @@ -15,7 +30,8 @@ def bc_getutxo(address, ramount, page=1, retval=None, avail=0):
if retval==None:
retval=[]
try:
r = requests.get('https://api.blocktrail.com/v1/btc/address/'+address+'/unspent-outputs?api_key='+str(BTAPIKEY)+'&limit=200&page='+str(page))
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))
if r.status_code == 200:
response = r.json()
unspents = response['data']
Expand All @@ -40,7 +56,8 @@ def bc_getutxo(address, ramount, page=1, retval=None, avail=0):

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

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

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

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


def bc_getpubkey(address):
# note: only supports mainnet
try:
r = requests.get('https://blockchain.info/q/pubkeyaddr/'+address)
if config.TESTNET:
return "error: tried using blockchain.info api with testnet enabled"

r = requests.get(BLOCKCHAININFO_API_URL + '/q/pubkeyaddr/'+address)

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

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

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

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

try:
r = requests.post('https://www.blockonomics.co/api/balance',json.dumps({"addr":formatted}))
if config.TESTNET:
return "error: tried using blockonomics api with testnet enabled"

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

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

r= requests.get(BLOCKCHAININFO_API_URL + '/balance?active='+formatted)
if r.status_code == 200:
balances = r.json()
retval = {}
Expand Down
37 changes: 37 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
RECAPTCHA_PRIVATE = None #replace private key text here
DOMAIN = None #Replace with domain to override email domain lookup, otherwise system hostname is used
EMAILFROM = "[email protected]" #Is set to None, use noreply@domain
SMTPUSER = "[email protected]" #If your smtp server requires authentication define it here
SMTPPASS = "8473aba8f839e68810f890613be7213e" #If your smtp server requires authentication define it here
SMTPDOMAIN = 'smtp.mailgun.org' #smtp server to use for sending, default 'localhost'
SMTPPORT = 25 #smtp port, default 25
SMTPSTARTTLS = True # Use starttls before SMTP login
WELCOMECID = None #mailgun campaign id for welcome email stats

#For wallets and session store you can switch between disk and the database
LOCALDEVBYPASSDB = 0 #Set to 1 to use local storage/file system, Set to 0 to use database

#Used to generate challange/response hash
SERVER_SECRET = 'SoSecret!'
SESSION_SECRET = 'SuperSecretSessionStuff'
WEBSOCKET_SECRET = 'SocketSecret!'

#used for encrypting/decrypting secure values.
#NOTE: If these values change, anything previously encrypted with them will need to be updated / encrypted with the new values
AESKEY='aaaaaaaabbbbbbbb'
AESIV='aaaaaaaabbbbbbbb'

#Donation Address Pubkey (We need the pubkey so that if an address hasn't sent a tx before we don't need the private key to get the pubkey)
D_PUBKEY = '04ec31f456cc70a60793ff2033d9d2094541a5de8cac67ab1e5b1441187c6bed1601dc64c447244618268af0bd449d90d2ce71816efc69dc7921a226ed60fe926b'

#Blocktrail API Key (used for lookups of utxo's)
BTAPIKEY = None

#Redis Connection Info
REDIS_HOST='172.31.11.207'
REDIS_PORT=6379

REDIS_DB=0
REDIS_ADDRSPACE=""

TESTNET = True
3 changes: 3 additions & 0 deletions api/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ 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: 2 additions & 1 deletion api/rpcclient.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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,6 +7,7 @@
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 @@ -18,8 +19,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'] in ['true', 'True'] ):

if 'testnet' in response_dict and ( response_dict['testnet'][0] in ['true', 'True'] ):
testnet =True
magicbyte = 111
else:
Expand All @@ -32,8 +33,6 @@ 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 @@ -103,6 +102,7 @@ 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: 27 additions & 0 deletions www/assets/img/icons/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<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 @@ -114,6 +116,7 @@
<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: 14 additions & 7 deletions www/js/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,20 @@ function Login($injector, $scope, $http, $location, $modalInstance, $q, Account,
});
} else {

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);
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);
})
}
};
Expand Down
56 changes: 52 additions & 4 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",
function WalletOverviewController($scope,$location,Wallet,ModalManager,$filter){
.controller("WalletOverviewController", ["$scope","$location","Wallet","ModalManager","$filter", "$http",
function WalletOverviewController($scope,$location,Wallet,ModalManager,$filter, $http){
$scope.uuid = $scope.account.uuid;
$scope.loginLink = $location.protocol() + "://" + $location.host() + "/login/" + $scope.uuid;
//console.log(Wallet.addresses);
Expand Down Expand Up @@ -49,10 +49,31 @@ 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 @@ -72,4 +93,31 @@ 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 bf71cde

Please sign in to comment.