This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #832 from chain-engineering/master
My first instant answer that displays the balance of a Bitcoin addresses ready to go!
- Loading branch information
Showing
5 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |