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

examples/wallet_force_fee.js   A

Complexity

Total Complexity 16
Complexity/F 2

Size

Lines of Code 85
Function Count 8

Duplication

Duplicated Lines 85
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
wmc 16
nc 2
mnd 2
bc 17
fnc 8
dl 85
loc 85
rs 10
bpm 2.125
cpm 2
noi 13
c 1
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A client.initWallet 23 23 2
A client.createNewWallet 17 17 2
B wallet_force_fee.js ➔ sendTransaction 24 24 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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