Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit e009016

Browse files
authored
Merge pull request #229 from Bitcoin-com/stage
v4.2.0
2 parents 75a5e22 + b88e63d commit e009016

20 files changed

Lines changed: 538 additions & 342 deletions

gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242
// gtmPreview: "YOUR_GOOGLE_TAGMANAGER_ENVIROMENT_PREVIEW_NAME",
4343
},
4444
},
45-
'gatsby-plugin-offline',
45+
`gatsby-plugin-remove-serviceworker`,
4646
`gatsby-plugin-styled-components`,
4747
`gatsby-plugin-sharp`,
4848

gatsby-node.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,32 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
4141
if (isDoc) {
4242
let product = 'other'
4343

44+
// get sdk
4445
const isBitbox = filePath.includes('/bitbox/')
4546
const isSlp = filePath.includes('/slp/')
4647
const isGui = filePath.includes('/gui/')
4748
const isRest = filePath.includes('/rest/')
4849
const isBadger = filePath.includes('/badger/')
4950

51+
// get platform
52+
const isJs = filePath.includes('/js/')
53+
const isAndroid = filePath.includes('/android/')
54+
const isiOS = filePath.includes('/ios/')
55+
5056
if (isBitbox) {
5157
slug = `/bitbox/docs/${filename}`
5258
product = 'bitbox'
5359
}
5460
if (isSlp) {
55-
slug = `/slp/docs/${filename}`
61+
if (isJs) {
62+
slug = `/slp/docs/js/${filename}`
63+
} else if (isAndroid) {
64+
slug = `/slp/docs/android/${filename}`
65+
} else if (isiOS) {
66+
slug = `/slp/docs/ios/${filename}`
67+
} else {
68+
slug = `/slp/docs/${filename}`
69+
}
5670
product = 'slp'
5771
}
5872
if (isGui) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "developer.bitcoin.com",
33
"description": "Bitcoin.com developer resources and documentation",
4-
"version": "4.1.0",
4+
"version": "4.2.0",
55
"author": "Peter <peter@bitcoin.com> and Gabriel Cardona <gabriel@bitcoin.com>",
66
"dependencies": {
77
"badger-components-react": "^0.3.0",
@@ -10,8 +10,8 @@
1010
"gatsby-plugin-flow": "^1.0.2",
1111
"gatsby-plugin-google-tagmanager": "^2.0.9",
1212
"gatsby-plugin-manifest": "^2.0.19",
13-
"gatsby-plugin-offline": "^2.0.24",
1413
"gatsby-plugin-react-helmet": "^3.0.7",
14+
"gatsby-plugin-remove-serviceworker": "^1.0.0",
1515
"gatsby-plugin-robots-txt": "^1.4.0",
1616
"gatsby-plugin-sharp": "^2.0.22",
1717
"gatsby-plugin-sitemap": "^2.0.6",

src/data/docs/badger/badger-components-react.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Like other components, components enhanced with BadgerBase are free to add any o
226226

227227
```js
228228
import React from 'react'
229-
import { BadgerBase, formatAmount } from 'badger-react-components'
229+
import { BadgerBase, formatAmount } from 'badger-components-react'
230230

231231
import styled from 'styled-components'
232232

@@ -236,10 +236,10 @@ const CoolButton = styled.button`
236236
border-radius: 24px;
237237
`
238238

239-
const MyButton extends React.Component {
239+
class MyButton extends React.Component {
240240
render() {
241241
// Props from higher order component
242-
const {handleClick, to, price, currency, amount, coinDecimals step} = this.props;
242+
const { handleClick, to, price, currency, amount, coinDecimals, step } = this.props;
243243
return (
244244
<div>
245245
<h3>Donate {price}{currency} to {to}</h3>

src/data/docs/bitbox/address.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,26 +627,27 @@ Return details about an address including balance.
627627

628628
### `utxo`
629629

630-
Return list of uxto for address
630+
Return list of uxto for address. This includes confirmed and unconfirmed utxos.
631631

632632
#### Arguments
633633

634-
- addresses (required):
634+
- addresses (required) - 2 formats allowed:
635635
- `String`: A single string containing a legacy or cash address.
636636
- `Array` of strings: Array with maximum of 20 legacy or cash addresses.
637637

638638
#### Result
639639

640-
- utxo:
640+
- utxo (2 formats based on the argument format):
641641
- utxo `Object`: containing `utxo` array of utxos, plus `legacyAddress`,
642642
`cashAddress` and `scriptPubKey` properties.
643-
- utxos `Array`: Array of utxo Objects.
643+
- utxos `Array`: Array of utxo Objects. <br>
644+
Each utxo `object` contains the following keys: `txid` as the transaction ID where that utxo appeared, `vout`: the index of this utxo in the list of outputs, `amount`: the amount sent to that utxo in BCH (decimal number, `satoshis`: the amount sent to that utxo in satoshis (1 satoshi = 0.00000001 BCH), `height`: the block in which the transaction is stored, `confirmations`: the number of confirmations (which is equal to current block height - `height`). For unconfirmed transactions, `confirmations` = 0 and the `height` key is replaced by a `ts` key with the time stamp of when the transaction was received in the mempool (Unix timestamp based on seconds since standard epoch of 1/1/1970).
644645

645646
#### Examples
646647

647648
(async () => {
648649
try {
649-
let utxo = await BITBOX.Address.utxo(['1M1FYu4zuVaxRPWLZG5CnP8qQrZaqu6c2L']);
650+
let utxo = await BITBOX.Address.utxo('1M1FYu4zuVaxRPWLZG5CnP8qQrZaqu6c2L');
650651
console.log(utxo);
651652
} catch(error) {
652653
console.error(error)
@@ -741,7 +742,7 @@ Return list of unconfirmed transactions for address
741742

742743
(async () => {
743744
try {
744-
let unconfirmed = await BITBOX.Address.unconfirmed(['1JCwsMQtiV85fGjps4zXceaCCgxpQ1u84R']);
745+
let unconfirmed = await BITBOX.Address.unconfirmed('1JCwsMQtiV85fGjps4zXceaCCgxpQ1u84R');
745746
console.log(unconfirmed);
746747
} catch(error) {
747748
console.error(error)

src/data/docs/bitbox/ecpair.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ ordinal: 9
66

77
### `fromWIF`
88

9-
Generates an ECPair from a private key in wallet import format.
9+
Generates an ECPair from a private key in wallet import format ([WIF](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#private-key-formats)). Follow these [steps to go from a private key to a WIF](https://en.bitcoin.it/wiki/Wallet_import_format). This method only works with a [compressed private key](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#compressed-private-keys).
1010

1111
#### Arguments
1212

13-
1. wif `string`: private key in wallet import format (WIF)
13+
1. wif `string`: private key in wallet import format ([WIF](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#private-key-formats))
1414

1515
#### Result
1616

src/data/docs/bitbox/transactionBuilder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Set [locktime](https://developer.bitcoin.com/mastering-bitcoin-cash/4-transactio
9898

9999
### `sign`
100100

101-
Sign transaction
101+
Sign transaction. It creates the unlocking script needed to spend an input. Each input has its own script and thus 'sign' must be called for each input even if the keyPair is the same.
102102

103103
#### Arguments
104104

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
title: Android
3+
icon: android
4+
ordinal: 7
5+
---
6+
7+
### Github repo
8+
9+
[slp-wallet-sdk-android](https://github.com/Bitcoin-com/slp-wallet-sdk-android)
10+
11+
### Supported Android Versions
12+
13+
5.0+
14+
15+
#### Warning
16+
17+
On Android versions prior to Android 6.0 Marshmallow, disabling the secure lock screen (reconfiguring it to None, Swipe, or another mode which does not authenicate the user) will have the following conquences:
18+
19+
- Loss of the BCH and tokens held at the wallet address.
20+
- Loss of access to the private key that controls the BCH and tokens held at the wallet address.
21+
22+
Tokens and any extra BCH at the wallet address can only be recovered if the mnemonic has been previously backed up.
23+
24+
### Installation
25+
26+
#### Gradle
27+
28+
Add JitPack to the list of repositories in your top level `build.gradle` file for the project:
29+
30+
```groovy
31+
allprojects {
32+
repositories {
33+
google()
34+
jcenter()
35+
maven { url 'https://jitpack.io' } // Add this repository
36+
}
37+
}
38+
```
39+
40+
In the module 'build.gradle' file, add the dependency:
41+
42+
```groovy
43+
dependencies {
44+
// ...
45+
46+
implementation 'com.github.Bitcoin-com:slp-wallet-sdk-android:0.4'
47+
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
48+
49+
}
50+
```
51+
52+
Excluding guava is required to avoid conflicts.
53+
54+
##### Binary compatibility
55+
56+
In the current version of the SDK, some items need to be removed for binary compatibility.
57+
58+
Add these packaging options to your module `build.gradle`.
59+
60+
```groovy
61+
android {
62+
// ...
63+
64+
packagingOptions {
65+
exclude 'lib/x86_64/darwin/libscrypt.dylib'
66+
exclude 'lib/x86_64/freebsd/libscrypt.so'
67+
exclude 'lib/x86_64/linux/libscrypt.so'
68+
}
69+
}
70+
```
71+
72+
### Get Started
73+
74+
```kotlin
75+
import com.bitcoin.slpwallet.SLPWallet
76+
77+
// Create a new wallet on mainnet, or load one previously created.
78+
val slpWallet: SLPWallet = SLPWallet.loadOrCreate(context, Network.MAIN)
79+
80+
val slpWalletFromPhrase: SLPWallet = SLPWallet.fromMnemonic(
81+
context,
82+
Network.MAIN
83+
"rare genre crumble sport burger laugh lecture reject exhaust hello express pass"
84+
)
85+
86+
// A wallet is created on mainnet if one does not exist already.
87+
val slpWallet: SLPWallet = SLPWallet.getInstance(context)
88+
```
89+
90+
### Addresses + Mnemonic
91+
92+
The wallet resuses two addresses that shares mnemonic.
93+
94+
- The SLP address on m/44'/245'/0'/0/0.
95+
- The BCH address on m/44'/145'/0'/0/0.
96+
97+
All BCH change will be sent to the BCH address while all token change is sent to the SLP address, separating the two if they were not already. This helps protect against accidental spending of BCH that contains SLP, by wallets are not aware of SLP, which would result in loss of coins.
98+
99+
```kotlin
100+
slpWallet.mnemonic // "rare", "genre", "crumble", "sport", "burger", "laugh", "lecture", "reject", "exhaust", "hello", "express", "pass"
101+
slpWallet.slpAddress // simpleledger:qr6wa5eemn0fl3vghvk5cr480s3fqtgnevkaxny9x7
102+
slpWallet.bchAddress // bitcoincash:qr6wa5eemn0fl3vghvk5cr480s3fqtgnev6xdg39cq
103+
104+
```
105+
106+
#### Token and BCH Balances
107+
108+
The balances, including both tokens and BCH, are available as LiveData.
109+
110+
```kotlin
111+
slpWallet.balance.observe(this, Observer { balanceList: List<BalanceInfo> ->
112+
var balances = ""
113+
for (balance in balanceList) {
114+
val nf = getTokenNumberFormat(balance.decimals, balance.ticker)
115+
balances += "${nf.format(balance.amount)}\n"
116+
}
117+
balancesText.text = balances
118+
})
119+
```
120+
121+
The BCH balance item has an emtpy `tokenId` of `""`.
122+
123+
```kotlin
124+
interface BalanceInfo {
125+
var tokenId: String
126+
var amount: BigDecimal
127+
var ticker: String?
128+
var name: String?
129+
var decimals: Int?
130+
}
131+
```
132+
133+
To refresh the current balance:
134+
135+
```kotlin
136+
slpWallet.refreshBalance()
137+
```
138+
139+
### Send Token
140+
141+
```kotlin
142+
private val compositeDisposable = CompositeDisposable()
143+
144+
// ...
145+
146+
val tokenId = "73bf34eb6cd6879fc75b0e91ad82ef61a6bf2f10adb38a067a25b30f9a644cea"
147+
val amount = BigDecimal(1)
148+
val toAddress = "simpleledger:qpfp0tfafxfq52mdpperlyschmmh6scfgse80v7a4p"
149+
150+
slpWallet.sendToken(tokenId, amount, toAddress)
151+
.subscribeOn(Schedulers.io())
152+
.subscribe(
153+
{ txid: String ->
154+
Timber.d("sendToken() was successful, with txid: $txid")
155+
},
156+
{ e: Throwable ->
157+
Timber.e("Error when sending. $e")
158+
}
159+
).addTo(compositeDisposable)
160+
```
161+
162+
The example above uses Rx, but the status of the send task is also available as LiveData:
163+
164+
```kotlin
165+
slpWallet.sendStatus.observe(this, Observer { task: ProgressTask<String?> ->
166+
var sendStatus = ""
167+
when (task.status) {
168+
TaskStatus.IDLE -> {
169+
sendStatus = ""
170+
}
171+
TaskStatus.UNDERWAY -> {
172+
sendStatus = "Sending..."
173+
}
174+
TaskStatus.SUCCESS -> {
175+
sendStatus = "Sent tx ${task.result}"
176+
}
177+
TaskStatus.ERROR -> {
178+
sendStatus = "Error. ${task.message}"
179+
}
180+
}
181+
sendStatusText.text = sendStatus
182+
})
183+
```
184+
185+
Once a send has been completed, you can reset the status to `IDLE`:
186+
187+
```kotlin
188+
slpWallet.clearSendStatus()
189+
```
190+
191+
### UI
192+
193+
Some convenience methods are included to make it easier to display tokens in your UI.
194+
195+
#### Formatting Amounts
196+
197+
This will display the amount to the full number of decimal places permitted by the coin, preceded by the ticker.
198+
199+
```kotlin
200+
import com.bitcoin.slpwallet.getTokenNumberFormat
201+
202+
val nf: NumberFormat = getTokenNumberFormat(decimals, ticker)
203+
val text: String = nf.format(amount) // "AAR 123.45"
204+
```
205+
206+
### Logging
207+
208+
This library uses [Timber](https://github.com/JakeWharton/timber) for logging, but does not plant it's own tree. Plant a tree like this when your application starts to see the logs:
209+
210+
```kotlin
211+
override fun onCreate(savedInstanceState: Bundle?) {
212+
super.onCreate(savedInstanceState)
213+
214+
if (BuildConfig.DEBUG) {
215+
Timber.plant(Timber.DebugTree())
216+
}
217+
218+
// ...
219+
}
220+
```

0 commit comments

Comments
 (0)