Skip to content

BaerChain pendingOrder transaction

weidong edited this page Apr 9, 2020 · 4 revisions

Pending transaction(pendingOrder)

1. Request Json file description Back Dir

  • pendingOrder.json, File description
{
    "source":[
    {
	"from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
	"to":"0x00000000000000000000000000000000766f7465",
	"value":"0",
	"data":[
	{
	    "type":3,
	    "m_from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
	    "m_type":2,
	    "m_token_type":1,
	    "m_buy_type":0,
	    "m_num":"0x0",
	    "m_price":"0xf4240"
	}
	],
	"chainId":"0x1",
	"nonce":"0x0",
	"gas":"0x9c40",
	"gasPrice":"0x5"
    }
    ],
    "keys":[
	"8kZJMg3BfpkD6yzWh84N2ACPZaqWSZof1G23YQ7PD3u6"
    ]
}
  • You can view the code for json assembly
  • Parameter Description
    • Remarks: When to fill in another address, and data is not empty, the default to is the contract address of the call, and transfer the value of the value from (from value if there is a value) to to, generally prohibit this operation
from     :string, Pending order originating address
to       :string, Fixed address, cannot be changed
value    : string, default: "0x0"
data     : string, Pending order details
           > type         : int, Fixed at 3, indicating pending order
           > m_from       : string, Pending order initiation address, same as from
           > m_type       : int, (1 : sell,2 : buy)
           > m_token_type : int, Currency(1 : cookie)
           > m_buy_type   : int, Price type (0: market price, 1: limit price)
                            Note: (1) When m_buy_type is 1, m_num and m_price cannot be 0
                                  (2) m_type is 2, m_buy_type is 0, m_num is 0, and m_pirce cannot be 0
				                  (3) m_type is 1, m_buy_type is 0, m_num cannot be 0, m_pirce is 0
                                  (4) When placing an order at market price (ie, when m_buy_type is 0), there must be a corresponding order in the trading pool that can match it successfully.
           > m_num        : string, hexadecimal, the number of purchases and sales (cookies) (quantity is 8-bit precision, that is, 1 cookie is 100000000; the minimum value can be 10000, which means 0.0001 cookies; the value conversion of m_num is specified (It must end with 4 zeros in decimal)
           > m_price      : string, hexadecimal. When m_buy_type is 1, it is the unit price for buying and selling each cookie (unit price is 8-digit precision, that is, unit price 1 is 100000000; the minimum value that can be passed in is 10000, which represents unit price 0.0001; When the value of m_price is converted to decimal, it must end with 4 0s)
                            When m_buy_type is 0, it is the total price of buying and selling cookies (the total price is 8-digit precision, 100000000 when launching a transaction is 1 cookie, the minimum value that can be passed in is 10000, which means 0.0001 cookies;
							At this time, it is stipulated that when the value of m_price is converted to decimal, it must end with 4 0s. Note that when the pending order address does not have a cookie, the pending purchase of the cookie is not enough to pay the gas fee after the transaction is completed, the pending order is not successful)

chainId  : string, Hexadecimal, chain ID, must be the same as chain creation chainId
nonce    : string, Hexadecimal, nonce value, +1 after each execution
gas      : string, Hexadecimal, the gas integer provided for transaction execution
gasPrice : string, Hexadecimal, for each gasPrice integer paid for gas
  • Remarks: When buying a cookie with a limit order, the total amount of BRC spent = the number of cookies bought * the unit price bought with BRC> = 0xe8d4a51000(Change to decimal, and 8-digit precision, that is 10000 BRC) to place a pending order, that is BRC = m_num * m_price> = 0xe8d4a51000
  • Remarks: When selling a cookie with a limit order, the total cost of the cookie = the number of cookies sold * The unit price sold with BRC> = 0xe8d4a51000(Change to decimal, and 8-digit precision, that is 10000 BRC) to place a pending order, ie cookie = m_num * m_price> = 0xe8d4a51000

2. Pending order process description Back Dir

2.1 Confirm balance Back Dir

  • Description: Check the address balance to confirm whether the balance can be used for pending order transactions

    • address: 0xc6f73c3b14456434c7db388bcb4fd47377c0d738 buy cookies at market price
  • command

     curl -d '{"jsonrpc":"2.0","id":9,"method":"brc_getBalance","params":["c6f73c3b14456434c7db388bcb4fd47377c0d738","latest"]}'  127.0.0.1:8111
    
  • Return result

     {
     	"id": 9,
     	"jsonrpc": "2.0",
     	"result": {
     		"Address": "c6f73c3b14456434c7db388bcb4fd47377c0d738",
     		"BRC": "0x9184e72a000",(Converted to decimal 10000000000000, because 8 is precision, so there are 100,000 BRC)
     		"FBRC": "0x0",
     		"FBalance": "0x0",
     		"balance": "0x0", (You can see that the cookie is 0)
     		"ballot": "0x0",
     		"cookieinsummury": "0x0",
     		"nonce": "0x0",
     		"poll": "0x0",
     		"vote": null
     	}
     }
    
  • Remarks: When there is no cookie at present, you can buy a cookie with a market order by buying a cookie. After the matching of the pending order will automatically deduct the gas consumed

2.2 Buy cookies at market price Back Dir

  • Execution instruction example (the same in 4 ways)
../cmdWallet -j ./pendingOrder.json -s 127.0.0.1:8111
  • cmdWallet: Perform file acquisition
cd cpp-lsac/build : Enter the directory
cmake ..          : Execute instruction
make              : Execute instruction
cd cpp-lsac/build/wallet/cmdWallet : You can find the cmdWallet executable file just compiled in this directory
  • 地址c6f73c3b14456434c7db388bcb4fd47377c0d738以市价买cookie
{
	"from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
	"to":"0x00000000000000000000000000000000766f7465",
	"value":"0",
	"data":[
	    {
		"type":3,
		"m_from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
		"m_type":2,           (2 means buy)
		"m_token_type":1,     (1 means cookie)
		"m_buy_type":0,       (0 means market price)
  		"m_num":"0x0",        (At this time, the default is 0)
		"m_price":"0x2540be400" (At this time, m_price represents the total number of BRCs used to buy cookies, which is converted to 10000000000 in decimal,
                                 because of 8-bit precision, you can get 100 BRC market prices to buy cookies)
	     }
	 ],
	"chainId":"0x1",
	"nonce":"0x1",
	"gas":"0x9c40",
	"gasPrice":"0x5"
}
  • Check the current address balance
{
    "id": 9,
    "jsonrpc": "2.0",
    "result": {
	"Address": "c6f73c3b14456434c7db388bcb4fd47377c0d738",
	"BRC": "0x915fa66bc00",  (Converted to decimal 9990000000000, because it is 8 for precision, so it is 99900 BRCs, because 100 BRCs are used to buy cookies)
	"FBRC": "0x0",
	"FBalance": "0x0",
	"balance": "0x253bd0e0c", (Represents the number of cookies, converted to decimal 1099983433420, because it is 8 for precision, so after deducting the gas fee,
                                 At this time, 99.9483342 cookies are obtained. Of course, due to different market prices, the number of cookies obtained will be different.
                                    The specific is based on the actual situation, this time it is used for testing to help everyone understand)
	"ballot": "0x0",
 	"cookieinsummury": "0x0",
	"nonce": "0x1",
	"poll": "0x0",
	"vote": null
     }
}
  • At this point, we have enough BRC and cookies, then test the limit price to buy cookies

2.3 Buy cookies at limit price Back dir

  • address: c6f73c3b14456434c7db388bcb4fd47377c0d738 buy cookies at a limit price
{
    "from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
    "to":"0x00000000000000000000000000000000766f7465",
    "value":"0x0",
    "data":[
	{
		"type":3,
		"m_from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
		"m_type":2,           (2 means buy)
		"m_token_type":1,     (1 means cookie)
		"m_buy_type":1,       (1 means limit price)
		"m_num":"0xe8d4a51000",  (Convert to decimal to get 1000000000000, 8-bit precision is 1, which means buying 10000 cookies)
		"m_price":"0x5f5e100" (Converted to decimal to get 100000000, 8-bit precision is 1, at this time the unit price of buying cookies is 1 BRC)
                                    > (1) It can be seen that at this time, the price is limited to buy cookies with BRC. The number of cookies is 10,000 and the unit price is 1 BRC, then the quantity is multiplied by the unit price.
                                         That is 10000 * 1 = 10000, indicating that at this time I want to spend 10000 BRC to buy 10000 cookies
                                    > (2) If I want to buy 1000000 cookies, the unit price is still 1 BRC, then the quantity is multiplied by the unit price.
                                          That is 1000000 * 1 = 1000000, indicating that at this time I want to spend 1000000 BRC to buy 1000000 cookies
                                    > (3)If there is a corresponding order in the sell order, the transaction will be matched successfully, I get the cookie I want, and others get the BRC needed.
                                          Of course, the specific needs are mainly based on actual needs, this test is convenient to help everyone understand
 	}
	],
    "chainId":"0x1",
    "nonce":"0x2",
    "gas":"0x13880",
    "gasPrice":"0x5"
}
  • Query balances(brc_getBalance)
{
	"id": 9,
	"jsonrpc": "2.0",
	"result": {
		"Address": "c6f73c3b14456434c7db388bcb4fd47377c0d738",
		"BRC": "0x82d25c1ac00", (Converted to decimal 8990000000000, because of 8-bit precision, it can be seen that there are now 89900 BRC)
		"FBRC": "0x0",
		"FBalance": "0x0",
		"balance": "0xeb0a922a48",(Converted to decimal as 1009494665800, because of 8-bit precision, it can be seen that there are now 10094.946658 cookies,
                                        indicate that you have just bought 10,000 cookies)
		"ballot": "0x0",
		"cookieinsummury": "0x0",
		"nonce": "0x2",
		"poll": "0x0",
		"vote": null
	}
}

2.4 Sell cookies at limit price Back dir

  • address: c6f73c3b14456434c7db388bcb4fd47377c0d738 sell cookies at a limit price
{
	"from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
	"to":"0x00000000000000000000000000000000766f7465",
	"value":"0x0",
	"data":[
	    {
		"type":3,
		"m_from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
		"m_type":1,           (1 means sell)
		"m_token_type":1,     (1 means cookie)
		"m_buy_type":1,       (1 means limit price)
		"m_num":"0xe8d4a51000",  (Convert to decimal to get 100000000, 8-bit precision is 1, at this time it means selling 10000 cookies)
		"m_price":"0x5f5e100" (Converted to decimal to get 100000000, 8-bit precision is 1, at this time the unit price of selling 1 cookie is 1 BRC)
	    }
	],
	"chainId":"0x1",
	"nonce":"0x3",
	"gas":"0x13880",
	"gasPrice":"0x5"
}
  • Query your balance
{
	"id": 9,
	"jsonrpc": "2.0",
	"result": {
		"Address": "c6f73c3b14456434c7db388bcb4fd47377c0d738",
		"BRC": "0x82d25c1ac00", (Converted to decimal 8990000000000, because of 8-bit precision, it can be seen that there are now 89900 BRC)
		"FBRC": "0x0",
		"FBalance": "0xe8d4a51000",(Converted to decimal to 1000000000000, 8-bit precision is 1, FBalance said that 10,000 cookies were frozen at this time, because the test of the pending order limit price just sold 10,000 cookies, but it has not been traded, and it is still on the selling order, so This cookie is frozen until the transaction is successful or the order is cancel)
		"balance": "0x235ea8b84",(Converted to decimal to 9494498180, 8-bit precision is 94.9449818 cookies, because just 10000 cookies were sold, as can be seen from the above)
		"ballot": "0x0",
 		"cookieinsummury": "0x0",
		"nonce": "0x3",
		"poll": "0x0",
		"vote": null
	}
}

2.5 Sell cookies at market price Back dir

  • When selling cookies at market price, if there is no corresponding purchase order at this time, the order will not be registered successfully
{
	"from":"0xcccc7a30bf688c060524dfd759fe2627ed3387bc",
	"to":"0x00000000000000000000000000000000766f7465",
	"value":"0",
	"data":[
		{
			"type":3,
			"m_from":"cccc7a30bf688c060524dfd759fe2627ed3387bc",
			"m_type":1,          (1 means sell)
			"m_token_type":1,    (1 means cookie)
			"m_buy_type":0,      (0 means market price)
			"m_num":"0x3b9aca00", (Convert to decimal to get 100000000, 8-bit precision is 1, at this time it means selling 1 cookie)
			"m_price":"0"
		}
	],
	"chainId":"0x1",
	"nonce":"0x4",
	"gas":"0x9c40",
	"gasPrice":"0x5"
}

Remarks: If the cookie is sold at the market price at this time, if there is no corresponding purchase order at this time, the check will be displayed.

{
	"error": {
		"code": 0,
		"data": null,
		"message": "verifyPendingorder failed :There is no order for the corresponding order pool!"
	},
	"id": 1,
	"jsonrpc": "2.0"
}

For more query interface of matching pending orders, please checkRPC Interface Document

Clone this wiki locally