Skip to content

Commit 381f126

Browse files
committed
added readme, added default DB file
1 parent bde36fb commit 381f126

File tree

3 files changed

+210
-1
lines changed

3 files changed

+210
-1
lines changed

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#Counterparty Gateway Prototype
2+
3+
This is a PHP based automated "vending machine" or "gateway" prototype/proof of concept for the Counterparty (XCP) protocol.
4+
5+
A Counterparty "Vending Machine" is a program which accepts one type of asset (BTC, XCP or other user created assets) and spits
6+
out another asset using a defined exchange rate. For example, sending 0.01 BTC and receiving back 1000 LTBcoin.
7+
8+
This prototype is intended for command line use only, there is no GUI or web interface at this moment.
9+
10+
##Features
11+
12+
* Send and receive both bitcoin and counterparty assets based on defined exchange rates
13+
* Accept multiple tokens at different exchange rates
14+
* Ability to automatically issue new tokens when the local supply runs out (requires source address to have ownership of the token in question)
15+
* Customizable fees and other options
16+
17+
##Requirements
18+
19+
* PHP 5.4
20+
* MySQL
21+
* Python 3.4
22+
* [Bitcoind](https://github.com/bitcoin/bitcoin)
23+
* [Counterpartyd](https://github.com/CounterpartyXCP/counterpartyd)
24+
* Your favorite flavour of linux!
25+
26+
##Installation
27+
28+
* Make sure you have an instance of both Bitcoind and Counterpartyd fully operational
29+
* Create a new MySQL database and import "db.sql"
30+
* Edit conf/config.php and fill out all the appropriate information
31+
32+
To setup your vending machine, you will first want to edit "crypto-gateway.php" (this process will be improved later)
33+
34+
Specifically, you will want to edit this section:
35+
36+
```
37+
$gateway = new Crypto_Gateway('1CoinEXLQtivDjckWMRBbhgVJk9RdwdYbR', 'BITCOINEX', array('BTC' => 1, 'XBTC' => 1));
38+
$gateway->allow_two_way = true;
39+
$gateway->auto_inflate = true;
40+
$gateway->inflation_mode = 'as_needed';
41+
$gateway->inflation_modifier = 1;
42+
```
43+
44+
Let's break this down line by line.
45+
46+
```
47+
$gateway = new Crypto_Gateway('1CoinEXLQtivDjckWMRBbhgVJk9RdwdYbR', 'BITCOINEX', array('BTC' => 1, 'XBTC' => 1));
48+
````
49+
50+
The first argument in this function is your **source address**, which is the address that outgoing transactions will be coming from. If you want it to automatically issue new tokens for you, you will need to make sure that the source address also has ownership rights to your desired token.
51+
52+
The second argument is the name of the primary token used by the vending machine, and can be either BTC, XCP or any Counterparty token. This is the main token that will be sent out after incoming transactions are confirmed.
53+
54+
The third argument is an array of which tokens are accepted and what the exchange rate is for them. In this default example, both regular BTC as well as the token "XBTC" are accepted for incoming transactions, with both of them having an equal 1:1 exchange rate. If ```'BTC' => 1 ``` was changed to ```'BTC' => 1000```, then sending 1 Bitcoin would cause 1,000 BITCOINEX to be vended out.
55+
56+
If you would like to have different addresses for receiving and sending transactions, you may add in the following line of code:
57+
``` $gateway->watch_address = 'MY_WATCH_ADDRESS'; ```
58+
59+
...
60+
61+
```
62+
$gateway->allow_two_way = true;
63+
```
64+
65+
If set to true, the vending machine will allow the **primary token** to be sent back and exchanged back to one of the accepted tokens. The first item in the array of accepted tokens is what will be sent back (in this example, BTC). Note that the service fee (if any defined) is only applied one way (e.g a fee is taken when vending BTC -> BITCOINEX, but no fee is taken with BITCOINEX -> BTC)
66+
67+
```
68+
$gateway->auto_inflate = true;
69+
$gateway->inflation_mode = 'as_needed';
70+
$gateway->inflation_modifier = 1;
71+
```
72+
73+
This section defines the auto issuance behavior. If you do not want the vending machine to attempt to issue new tokens when its supply runs out, just set "auto_inflate" to false. Auto issuance is triggered when there is not enough tokens left in the source address to satisfy a new vending transaction.
74+
75+
There are three inflation modes available (which also change what "inflation_modifier" does):
76+
77+
* "as_needed" - this mode creates only as many tokens as needed for whatever pending outgoing transactions, multiplied by the inflation_modifier. e.g 1,000 new tokens are needed, so only 1,000 new tokens are created.
78+
* "fixed" - this creates a fixed amount of new tokens. If inflation_modifier was set to 50,000, it would simply create 50,000 new tokens
79+
* "percent" - this increases the total existing token supply by X percent (inflation_modifier). e.g if inflation_modifier is set to 0.10 (10%) and there is already 100,000 tokens out in the wild, then an additional 10,000 would be issued.
80+
81+
**Other Options**
82+
83+
Note that some of these options are not actually used yet (will fix soon)
84+
85+
```
86+
$gateway->min_btc = 0.000055; //BTC dust limit, used mostly for if source token is just BTC
87+
$gateway->min_confirms = 1; //Min number of confirms before vending out token
88+
$gateway->miner_fee = 0.0001; //BTC miners fee
89+
$gateway->dust_size = 0.000055; //size to use for each dust output
90+
$gateway->service_fee = 0.5; //% fee to take off any incoming tokens
91+
92+
```
93+
94+
95+
##Usage
96+
97+
To start up the gateway/vending machine:
98+
99+
```
100+
php crypto-gateway.php > log &
101+
```
102+
``` > log &``` simply saves the output to a log file and runs the process in the background.
103+
104+
To view some basic stats on incoming/outgoing payments for each token used in the vending machine, run:
105+
106+
```
107+
php crypto-gateway.php stats
108+
```
109+
110+
If you want to send a transaction to your source/watch address (such as adding funds to pay for bitcoin fees, xcp for issuance fees, sending initial token supply etc.), but don't want to accidently trigger the gateway, you may add specific transactions to the "ignore list" by running the following command:
111+
112+
```
113+
php crypto-gateway.php ignore <transaction ID>
114+
```
115+
116+
**Running Multiple Gateways**
117+
118+
As this is mostly a proof of concept still, it hasn't had much testing or been fleshed out much. However, you should be able to create copies of "crypto-gateway.php" and change parameters etc. as needed and run them all simultaneously. They can all use the same database.
119+

db.sql

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- MySQL dump 10.13 Distrib 5.5.40, for debian-linux-gnu (x86_64)
2+
--
3+
-- Host: localhost Database: bitcoinex
4+
-- ------------------------------------------------------
5+
-- Server version 5.5.40-0ubuntu0.14.04.1-log
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `ignore_tx`
20+
--
21+
22+
DROP TABLE IF EXISTS `ignore_tx`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `ignore_tx` (
26+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
27+
`txId` varchar(255) NOT NULL,
28+
PRIMARY KEY (`id`),
29+
KEY `txId` (`txId`)
30+
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
31+
/*!40101 SET character_set_client = @saved_cs_client */;
32+
33+
--
34+
-- Table structure for table `issuances`
35+
--
36+
37+
DROP TABLE IF EXISTS `issuances`;
38+
/*!40101 SET @saved_cs_client = @@character_set_client */;
39+
/*!40101 SET character_set_client = utf8 */;
40+
CREATE TABLE `issuances` (
41+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
42+
`source` varchar(50) NOT NULL,
43+
`asset` varchar(100) NOT NULL,
44+
`amount` decimal(20,8) DEFAULT '0.00000000',
45+
`new_supply` decimal(20,8) DEFAULT '0.00000000',
46+
`txId` varchar(255) NOT NULL,
47+
`complete` int(1) DEFAULT '0',
48+
`issueDate` datetime DEFAULT NULL,
49+
PRIMARY KEY (`id`),
50+
KEY `source` (`source`),
51+
KEY `asset` (`asset`),
52+
KEY `txId` (`txId`)
53+
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
54+
/*!40101 SET character_set_client = @saved_cs_client */;
55+
56+
--
57+
-- Table structure for table `transactions`
58+
--
59+
60+
DROP TABLE IF EXISTS `transactions`;
61+
/*!40101 SET @saved_cs_client = @@character_set_client */;
62+
/*!40101 SET character_set_client = utf8 */;
63+
CREATE TABLE `transactions` (
64+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
65+
`type` varchar(20) NOT NULL,
66+
`source` varchar(50) NOT NULL,
67+
`destination` varchar(50) DEFAULT NULL,
68+
`amount` decimal(20,8) DEFAULT '0.00000000',
69+
`txId` varchar(255) DEFAULT NULL,
70+
`confirmed` int(1) DEFAULT '0',
71+
`txDate` datetime DEFAULT NULL,
72+
`asset` varchar(255) DEFAULT 'BTC',
73+
PRIMARY KEY (`id`),
74+
KEY `type` (`type`),
75+
KEY `source` (`source`),
76+
KEY `destination` (`destination`),
77+
KEY `txId` (`txId`)
78+
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;
79+
/*!40101 SET character_set_client = @saved_cs_client */;
80+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
81+
82+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
83+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
84+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
85+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
86+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
87+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
88+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
89+
90+
-- Dump completed on 2015-01-03 22:51:27

lib/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Crypto_Gateway extends Model
1919
private $accepted_info = array(); //stores any info for tokens being accepted for gateway
2020
private $btc_data = array('issuer' => false, 'supply' => 2100000000000000, 'description' => false,
2121
'locked' => true, 'divisible' => true, 'asset' => 'BTC', 'call_date' => false,
22-
'owner' => false, 'call_price' => false, 'callable' => false);
22+
'owner' => false, 'call_price' => false, 'callable' => false); //don't change this!
2323
private $ignore_tx = array();
2424

2525
/**

0 commit comments

Comments
 (0)