Fabcoin Core  0.16.2
P2P Digital Currency
ICAP.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
24 #pragma once
25 
26 #include <string>
27 #include <functional>
28 #include <boost/algorithm/string/case_conv.hpp>
29 #include <libdevcore/Common.h>
30 #include <libdevcore/Exceptions.h>
31 #include <libdevcore/FixedHash.h>
32 #include "Common.h"
33 
34 namespace dev
35 {
36 namespace eth
37 {
38 
39 DEV_SIMPLE_EXCEPTION(InvalidICAP);
40 
45 class ICAP
46 {
47 public:
49  ICAP() = default;
51  ICAP(Address const& _target): m_type(Direct), m_direct(_target) {}
53  ICAP(std::string const& _client, std::string const& _inst): m_type(Indirect), m_client(boost::algorithm::to_upper_copy(_client)), m_institution(boost::algorithm::to_upper_copy(_inst)), m_asset("XET") {}
55  ICAP(std::string const& _c, std::string const& _i, std::string const& _a): m_type(Indirect), m_client(boost::algorithm::to_upper_copy(_c)), m_institution(boost::algorithm::to_upper_copy(_i)), m_asset(boost::algorithm::to_upper_copy(_a)) {}
56 
58  enum Type
59  {
63  };
64 
66  static Secret createDirect();
67 
69  static std::string iban(std::string _c, std::string _d);
71  static std::pair<std::string, std::string> fromIBAN(std::string _iban);
72 
74  static ICAP decoded(std::string const& _encoded);
75 
77  std::string encoded() const;
79  Type type() const { return m_type; }
81  Address const& direct() const { return m_type == Direct ? m_direct : ZeroAddress; }
83  std::string const& asset() const { return m_type == Indirect ? m_asset : EmptyString; }
85  std::string const& target() const { return m_type == Indirect && m_asset == "ETH" ? m_client : EmptyString; }
87  std::string const& institution() const { return m_type == Indirect && m_asset == "XET" ? m_institution : EmptyString; }
89  std::string const& client() const { return m_type == Indirect && m_asset == "XET" ? m_client : EmptyString; }
91  std::pair<Address, bytes> address(std::function<bytes(Address, bytes)> const& _call, Address const& _reg) const { return m_type == Direct ? make_pair(direct(), bytes()) : m_type == Indirect ? lookup(_call, _reg) : make_pair(Address(), bytes()); }
92 
94  std::pair<Address, bytes> lookup(std::function<bytes(Address, bytes)> const& _call, Address const& _reg) const;
95 
96 private:
99  std::string m_client;
100  std::string m_institution;
101  std::string m_asset;
102 };
103 
104 
105 }
106 }
std::string encoded() const
Definition: ICAP.cpp:110
std::pair< Address, bytes > lookup(std::function< bytes(Address, bytes)> const &_call, Address const &_reg) const
Definition: ICAP.cpp:137
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::string m_asset
Definition: ICAP.h:101
static std::pair< std::string, std::string > fromIBAN(std::string _iban)
Definition: ICAP.cpp:55
#define function(a, b, c, d, k, s)
std::pair< Address, bytes > address(std::function< bytes(Address, bytes)> const &_call, Address const &_reg) const
Definition: ICAP.h:91
Definition: Log.h:35
std::string const & client() const
Definition: ICAP.h:89
ICAP(std::string const &_c, std::string const &_i, std::string const &_a)
Construct an indirect ICAP object for given client, institution and asset names. You generally don&#39;t ...
Definition: ICAP.h:55
ICAP(std::string const &_client, std::string const &_inst)
Construct an indirect ICAP object for given client and institution names.
Definition: ICAP.h:53
std::string m_institution
Definition: ICAP.h:100
h160 Address
An Ethereum address: 20 bytes.
Definition: Common.h:62
std::string const & asset() const
Definition: ICAP.h:83
std::string const & target() const
Definition: ICAP.h:85
static ICAP decoded(std::string const &_encoded)
Definition: ICAP.cpp:78
static std::string iban(std::string _c, std::string _d)
Definition: ICAP.cpp:38
std::string m_client
Definition: ICAP.h:99
std::string const & institution() const
Definition: ICAP.h:87
static Secret createDirect()
Create a direct address for ICAP.
Definition: ICAP.cpp:67
Type m_type
Definition: ICAP.h:97
Address ZeroAddress
The zero address.
Definition: Common.cpp:65
std::vector< byte > bytes
Definition: Common.h:75
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
ICAP(Address const &_target)
Construct a direct ICAP object for given target address. Must have a zero first byte.
Definition: ICAP.h:51
Encapsulation of an ICAP address.
Definition: ICAP.h:45
Address const & direct() const
Definition: ICAP.h:81
Address m_direct
Definition: ICAP.h:98
Type
Type of ICAP address.
Definition: ICAP.h:58
DEV_SIMPLE_EXCEPTION(InvalidSealEngine)
Type type() const
Definition: ICAP.h:79
ICAP()=default
Construct null ICAP object.