Completed
Push — master ( a4251b...3c3114 )
by Ruben de
01:08 queued 15s
created

client.createNewWallet   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
nop 3
1 View Code Duplication
var blocktrail = require('../'); // require('blocktrail-sdk') when trying example from in your own project
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
3
var client = blocktrail.BlocktrailSDK({
4
    apiKey : "MY_APIKEY",
5
    apiSecret : "MY_APISECRET",
6
    testnet : true
7
});
8
9
var sendTransaction = function(wallet) {
10
    wallet.getNewAddress(function(err, address, path) {
11
        if (err) {
12
            return console.log("getNewAddress ERR", err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
13
        }
14
15
        console.log('new address', address, path);
16
17
        var pay = {};
18
        pay[address] = blocktrail.toSatoshi(0.001);
19
20
        var options = {
21
            forcefee: blocktrail.toSatoshi(0.00054321)
22
        };
23
24
        wallet.pay(pay, null, true, true, blocktrail.Wallet.FEE_STRATEGY_FORCE_FEE, null, options, function(err, result) {
25
            if (err) {
26
                return console.log("pay ERR", err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
27
            }
28
29
            console.log('transaction', result);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
30
        });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
31
    });
32
};
33
34
var action = 'default';
35
36
if (action === 'create') {
37
    client.createNewWallet({
38
        identifier: "example-wallet",
39
        passphrase: "example-strong-password",
40
        keyIndex: 9999
41
    }, function(err, wallet, primaryMnemonic, backupMnemonic, blocktrailPubKeys) {
42
        if (err) {
43
            return console.log("createNewWallet ERR", err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
44
        }
45
46
        console.log('primary mnemonic', primaryMnemonic);
47
        console.log('backup mnemonic', backupMnemonic);
48
        console.log('blocktrail pubkeys', blocktrailPubKeys);
49
50
        wallet.getNewAddress(function(err, address, path) {
51
            if (err) {
52
                return console.log("getNewAddress ERR", err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
53
            }
54
55
            console.log('new address', address, path);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
56
        });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
57
    });
58
} else {
59
    client.initWallet({
60
        identifier: "example-wallet",
61
        readOnly: true
62
    }, function(err, wallet) {
63
        if (err) {
64
            console.log('initWallet ERR', err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
65
            throw err;
66
        }
67
68
        wallet.getBalance(function(err, confirmed, unconfirmed) {
69
            if (err) {
70
                return console.log("getBalance ERR", err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
71
            }
72
73
            console.log('confirmed balance', confirmed);
74
            console.log('unconfirmed balance', unconfirmed);
75
76
            wallet.unlock({passphrase: "example-strong-password"}, function(err) {
77
                if (err) {
78
                    return console.log("unlock ERR", err);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
79
                }
80
81
                sendTransaction(wallet);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
82
            });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
83
        });
84
    });
85
}
86