forked from mkaz/php-doge
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoged.php
More file actions
150 lines (124 loc) · 3.9 KB
/
Doged.php
File metadata and controls
150 lines (124 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Project : php-doged library
* Summary : A basic php library to talk with dogecoindarkd
*
* Source : forked from https://github.com/mkaz/php-doge
*
* Author : Marcus Kazmierczak (@mkaz)
* License : GPL vv
*/
require_once dirname( __FILE__ ) . '/jsonRPCClient.php';
class Doged {
private $client;
/**
* Create client to conncet on init
* @param $config array of parameters $host, $port, $user, $pass
*/
function __construct( $config ) {
$connect_string = sprintf( 'http://%s:%s@%s:%s/',
$config['user'],
$config['pass'],
$config['host'],
$config['port'] );
// internal client to use for connection
$this->client = new jsonRPCClient( $connect_string );
}
/**
* Creates or Retrieves a DogecoinDark address for a account name
* An account is just a string used as key to identify account,
* A DogecoinDark address is returned which can receive coins
*
* @param string $account some string used as key to account
* @return string dogecoin address
*/
function get_address( $account ) {
return $this->client->getaccountaddress( $account );
}
/**
* Given a DogecoinDark address returns the account name
*
* @param string $address dogecoin addresss
* @return string account name key
*/
function get_account( $address ) {
return $this->client->getaccount( $address );
}
/**
* Create new address for account, recommended to include
* account name for further API use.
*
* @param string $account account name
* @return string dogecoindark address
*/
function get_new_address( $account='' ) {
return $this->client->getnewaddress( $account );
}
/**
* Get list of all accounts on in this dogecoindarkd wallet
*
* @return array strings of account => balance
*/
function list_accounts() {
return $this->client->listaccounts();
}
/**
* Get the details of a transaction
*
* @param string $txid transaction id
* @return array describing the transaction
*/
function get_transaction( $txid ) {
return $this->client->gettransaction( $txid );
}
/**
* Associate dogecoindark address to account string
*
* @param string $address dogecoin address
* @param string $account account string
*/
function set_account( $address, $account ) {
return $this->client->setaccount($address, $account);
}
/**
* Get balance for given account
*
* @param string $account account name
* @return float account balance
*/
function get_balance( $account, $minconf=1 ) {
return $this->client->getbalance( $account, $minconf );
}
/**
* Move coins from one account on wallet to another
* Both accounts are local to this dogecoindarkd instance
*
* @param string $account_from account moving from
* @param string $account_to account moving to
* @param float $amount amount of coins to move
* @return
*/
function move( $account_from, $account_to, $amount ) {
return $this->client->move( $account_from, $account_to, $amount );
}
/**
* Send coins to any Dogecoindark Address
*
* @param string $account account sending coins from
* @param string $to_address dogecoindark address sending to
* @param float $amount amount of coins to send
* @return string txid
*/
function send( $account, $to_address, $amount ) {
$txid = $this->client->sendfrom( $account, $to_address, $amount );
return $txid;
}
/**
* Validate a given Dogecoindark Address
* @param string $address to validate
* @return array with the properties of the address
*/
function validate_address( $address ) {
return $this->client->validateaddress($address);
}
}