-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcurrencies_trait.php
91 lines (75 loc) · 2.17 KB
/
currencies_trait.php
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
<?php
namespace harmonypay;
/**
@brief Currency related information.
@since 2017-12-09 09:16:44
**/
trait currencies_trait
{
/**
@brief Return the currencies collection.
@since 2017-12-09 20:02:05
**/
public function currencies()
{
if ( isset( $this->__currencies ) )
return $this->__currencies;
$this->__currencies = new currencies\Currencies();
$action = $this->new_action( 'get_currencies' );
$action->currencies = $this->__currencies;
$action->execute();
return $this->__currencies;
}
/**
@brief Initialize the trait.
@since 2018-03-11 21:51:56
**/
public function init_currencies_trait()
{
$this->add_action( 'harmonypay_get_currencies', 5 ); // Before everyone else.
$this->add_action( 'harmonypay_use_wallet' );
}
/**
@brief Load our currencies from the account data.
@since 2018-03-11 21:44:32
**/
public function harmonypay_get_currencies( $action )
{
$currencies = $action->currencies; // Convenience
$account = $account = $this->api()->account();
//$this->debug( $account->get_currency_data());
foreach( $account->get_currency_data() as $currency_id => $currency_data )
{
// Needed for testing.
if ( isset( $currency_data->beta ) )
continue;
$currency = new \harmonypay\currencies\Currency();
// Use everything.
foreach( $currency_data as $key => $data )
$currency->$key = $data;
//HACK COIN ID
$currency->set_id( $currency_id );
$currency->set_name( $currency_data->name );
if ( isset( $currency_data->address_length ) )
$currency->set_address_length( $currency_data->address_length );
if ( isset( $currency_data->decimal_precision ) )
$currency->set_decimal_precision( $currency_data->decimal_precision );
if ( isset( $currency_data->group ) )
{
$group = new \harmonypay\currencies\Group();
$group->name = $currency_data->group;
$currency->set_group( $group );
}
$currencies->add( $currency );
}
}
/**
@brief harmonypay_use_wallet
@since 2018-07-01 14:25:15
**/
public function harmonypay_use_wallet( $action )
{
// Since the currency can't hook anything itself, we have to do it for it.
$action->currency->use_wallet( $action );
}
}