Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #832 from chain-engineering/master
Browse files Browse the repository at this point in the history
My first instant answer that displays the balance of a Bitcoin addresses ready to go!
  • Loading branch information
Jag Talon committed Jun 6, 2014
2 parents 865a1a7 + e82cde3 commit 2011304
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/DDG/Spice/BitcoinBalance.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package DDG::Spice::BitcoinBalance;
# ABSTRACT: Displays the balance of a Bitcoin address from the Chain.com API.

use DDG::Spice;

primary_example_queries "17x23dNjXJLzGMev6R63uyRhMWP1VHawKc", "1Gn2dRFqouUHvuWPVhriCDtP3qVQc59WHy", "3QJmV3qfvL9SuYo34YihAf3sRCW3qSinyC";
description "Display the balance of a Bitcoin address";
name "Bitcoin Address Balance";
source "http://chain.com";
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/BitcoinBalance.pm";
topics "economy_and_finance";
category "finance";
icon_url "https://chain.com/chain32x32.ico";

attribution github => ['https://github.com/chain-engineering','chain.com'],
email => ['[email protected]','[email protected]'],
twitter => "chain",
web => ['https://chain.com','chain.com'];

triggers query_raw => qr/^[13][1-9A-HJ-NP-Za-km-z]{26,33}$/;
# This regular expression identifies the unique properties of a Bitcoin Address.

spice to => 'https://api.chain.com/v1/bitcoin/addresses/$1?key={{ENV{BITCOIN_BALANCE_SPICE_APIKEY}}}';
# The Chain API requires an API key. Chain has granted the spice a free account with unlimited access. We can provide this to DuckDuckGo before release.

spice wrap_jsonp_callback => 1;

spice proxy_cache_valid => "418 1d";

handle query_raw => sub {
return $_;
};

1;
68 changes: 68 additions & 0 deletions share/spice/bitcoin_balance/bitcoin_balance.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.zci--bitcoinbalance .balance-wrapper {
overflow: auto;
padding-bottom: 6px;
}

.zci--bitcoinbalance .balance-box {
float: left;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #E9E9E9;
border-radius:3px;
padding: 2% 22px 3% 22px;
}

.zci--bitcoinbalance .btc-title {
position: relative;
float: left;
top: 18px;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
padding-right: 40px;
font-size: 15px;
}

.zci--bitcoinbalance .btc-balance {
position: relative;
float: right;
top: 5px;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
font-size: 35px;
}

.zci--bitcoinbalance .zci__more-at__icon {
padding-right: 0.45em;
}

@media screen and (max-width: 568px) {

.zci--bitcoinbalance .zci__body {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}

.zci--bitcoinbalance .balance-wrapper {
padding-bottom: 0;
}

.zci--bitcoinbalance .balance-box {
width: 100%;
padding: 2% 5% 3% 5%;
}
}

@media screen and (max-width: 480px) {
.zci--bitcoinbalance .btc-title {
top: 5px;
}

.zci--bitcoinbalance .btc-balance {
top: 3px;
font-size: 20px;
}
}
29 changes: 29 additions & 0 deletions share/spice/bitcoin_balance/bitcoin_balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(function (env) {
"use strict";
env.ddg_spice_bitcoin_balance = function(api_result){

if (!api_result || api_result.error) {
return Spice.failed('bitcoin_balance');
}

Spice.add({
id: "bitcoinBalance",
name: "Bitcoin Address",
data: {
balance: api_result.balance / 100000000.0
//The balance field on the API returns satoshis, so we divide by 100000000 to convert to BTC.
},
meta: {
sourceName: "Chain.com",
sourceUrl: "https://chain.com/bitcoin/addresses/" + api_result.hash
},
templates: {
group: 'info',
options:{
content: Spice.bitcoin_balance.content,
moreAt: true
}
}
});
};
}(this));
6 changes: 6 additions & 0 deletions share/spice/bitcoin_balance/content.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="clearfix balance-wrapper">
<span class="balance-box">
<span class="btc-title">BALANCE</span>
<span class="btc-balance">{{balance}} BTC</span>
</span>
</div>
20 changes: 20 additions & 0 deletions t/BitcoinBalance.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use DDG::Test::Spice;

ddg_spice_test(
[qw( DDG::Spice::BitcoinBalance )],
'17x23dNjXJLzGMev6R63uyRhMWP1VHawKc' => test_spice(
'/js/spice/bitcoin_balance/17x23dNjXJLzGMev6R63uyRhMWP1VHawKc',
call_type => 'include',
caller => 'DDG::Spice::BitcoinBalance',
proxy_cache_valid => "418 1d",
),
'17x23dNjXJLzGMev6R63uyRhMWP1VHawKc 1Gn2dRFqouUHvuWPVhriCDtP3qVQc59WHy' => undef,
'hello 1Gn2dRFqouUHvuWPVhriCDtP3qVQc59WHy' => undef
);

done_testing;

0 comments on commit 2011304

Please sign in to comment.