Pages:
Author

Topic: 300 BTC Coding Contest: Distributed Exchange (MasterCoin Developer Thread) - page 48. (Read 129207 times)

sr. member
Activity: 449
Merit: 250
Hi Tachikoma

Buyer 1EdAjiApS5cCpHdH4RKPMab1xmMVRWjLvk posted a
Buy   
TxID: 33644e6f24b29e1ef170d78ff04eab6f7e19368908edc6d477f9902697a71d67

But there is no confirmed payment transaction.   

When buyer posted a sell Transaction (.11 and .9 Test MSC) it is invalid because there was no payment yet for the first transaction.

After reparsing I only found one valid purchase

Buy .2 Test MSC for .003232 BTC
TxID: c7103de53a8ea3a20cec9a74543132f98302f75ab1868092e911dd5516f322a5
Confirm Payment TxID: 2bb54346f7d0ddfcb084451227089665bc1a7ebf8f0a9338d14d713592c268ed


Thanks for checking my data. I'm not sure I understand you correctly though. Could you try explaining it with examples what went wrong?


I can't find the transaction where    
1EdAjiApS5cCpHdH4RKPMab1xmMVRWjLvk sent  .00002 BTC to  16rAwebBXhJAM9ALf3fLFbaHKz24r2o3UN
If there is a payment the rest of the transaction will be valid.   It could be a bug in my implementation.

Here is an example
UserA places an advertisement to sell
UserB accepts UserA's  offer
(Note: UserB has not paid UserA)

UserB places an advertisement to sell
UserC accepts UserB's offer
UserC pays UserB


Since UserB has not paid UserA the transaction of UserB with UserC is invalid.








hero member
Activity: 938
Merit: 1000
There is no price per coin in the transaction data, only the number for sale and a total price.  We get price per coin by total price / number for sale.

For the block time limit - this is not how long the sell offer is valid for, it's how long the buyer has to make payment after their accept/'Purchase Offer' is accepted & first in a block.  I don't think too many sellers are going to want to post a sell offer allowing more than 1.77 days for the buyer to make payment Smiley During testing between 6 and 10 has been a good value.

Thanks for clarifying.

As I understand the chosen procedure, in order to sell mastercoins, we need 3 tx:
1. Sell offer.
2. Sell accept (that's a better name than purchase offer).
3. Actual payment.

If the buyer doesn't pay within the allowed time, the sell order simply continues (and the next buyer gets the mastercoins).
If there is an earlier buyer (who actually pays) all later accepts are ignored.



Basically, yes.

Just know that you don't have to buy a whole Purchase Offer in one go. You can just buy a couple of coins which means that the next person buying might also get the coins if there were enough.
sr. member
Activity: 284
Merit: 250
There is no price per coin in the transaction data, only the number for sale and a total price.  We get price per coin by total price / number for sale.

For the block time limit - this is not how long the sell offer is valid for, it's how long the buyer has to make payment after their accept/'Purchase Offer' is accepted & first in a block.  I don't think too many sellers are going to want to post a sell offer allowing more than 1.77 days for the buyer to make payment Smiley During testing between 6 and 10 has been a good value.

Thanks for clarifying.

As I understand the chosen procedure, in order to sell mastercoins, we need 3 tx:
1. Sell offer.
2. Sell accept (that's a better name than purchase offer).
3. Actual payment.

If the buyer doesn't pay within the allowed time, the sell order simply continues (and the next buyer gets the mastercoins).
If there is an earlier buyer (who actually pays) all later accepts are ignored.

sr. member
Activity: 266
Merit: 250
I am adding now the parsing of sell/buy offers to mastercoin-tools, and I start with this tx:
https://blockchain.info/tx/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34

Code:
$ python msc_parse.py -t 49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34 -d
[D] main: multisig tx found: 49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34
[I] parse_multisig: ['0001000000140000000200000000773594000000000000004e2006000000000000', '000200271000000000000000000000000000000000000000000000000000000000']
[I] parse_multisig: {'tx_hash': '49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34', 'tx_type_str': 'Sell offer', 'formatted_bitcoin_amount_desired': '0.00020000', 'currencyId': '00000002', 'currency_str': 'Test Mastercoin', 'tx_method_str': 'multisig', 'amount': '0000000077359400', 'fee_required': '002710', 'block_time_limit': '06', 'formatted_amount': '20.00000000', 'bitcoin_amount_desired': '0000000000004e20', 'formatted_block_time_limit': '6', 'baseCoin': '00', 'formatted_fee_required': '0.00010000', 'dataSequenceNum': '01', 'transactionType': '00000014'}

I compare to http://mastercoin-explorer.com/transactions/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34 and it seems that most fields get parsed well, except for:
* Price per coin 0.00001 =>1000 = 0x3E8 ( I don't see any 3e8 on the first or second hexdata)

And I would like to discuss the amount of bytes allocated to each field:
* Bitcoin amount desired - data_script[36:52] (instead of the original "simple send" padding - no problem)
* Fee required - second_data_script[4:10] (limited with 0.16777215 BTC - seems enough)
* Block time limit - data_script[52:54] (limited with 255 blocks which is around 1.77 days - very short)


There is no price per coin in the transaction data, only the number for sale and a total price.  We get price per coin by total price / number for sale.

For the block time limit - this is not how long the sell offer is valid for, it's how long the buyer has to make payment after their accept/'Purchase Offer' is accepted & first in a block.  I don't think too many sellers are going to want to post a sell offer allowing more than 1.77 days for the buyer to make payment Smiley During testing between 6 and 10 has been a good value.

sr. member
Activity: 284
Merit: 250
I am adding now the parsing of sell/buy offers to mastercoin-tools, and I start with this tx:
https://blockchain.info/tx/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34

Code:
$ python msc_parse.py -t 49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34 -d
[D] main: multisig tx found: 49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34
[I] parse_multisig: ['0001000000140000000200000000773594000000000000004e2006000000000000', '000200271000000000000000000000000000000000000000000000000000000000']
[I] parse_multisig: {'tx_hash': '49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34', 'tx_type_str': 'Sell offer', 'formatted_bitcoin_amount_desired': '0.00020000', 'currencyId': '00000002', 'currency_str': 'Test Mastercoin', 'tx_method_str': 'multisig', 'amount': '0000000077359400', 'fee_required': '002710', 'block_time_limit': '06', 'formatted_amount': '20.00000000', 'bitcoin_amount_desired': '0000000000004e20', 'formatted_block_time_limit': '6', 'baseCoin': '00', 'formatted_fee_required': '0.00010000', 'dataSequenceNum': '01', 'transactionType': '00000014'}

I compare to http://mastercoin-explorer.com/transactions/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34 and it seems that most fields get parsed well, except for:
* Price per coin 0.00001 =>1000 = 0x3E8 ( I don't see any 3e8 on the first or second hexdata)

And I would like to discuss the amount of bytes allocated to each field:
* Bitcoin amount desired - data_script[36:52] (instead of the original "simple send" padding - no problem)
* Fee required - second_data_script[4:10] (limited with 0.16777215 BTC - seems enough)
* Block time limit - data_script[52:54] (limited with 255 blocks which is around 1.77 days - very short)


EDIT:
Price per coin is calculated from "amount" and "bitcoin amount desired".
My only question is not about "block time limit". Isn't it too short?

hero member
Activity: 938
Merit: 1000
Hi Tachikoma

Buyer 1EdAjiApS5cCpHdH4RKPMab1xmMVRWjLvk posted a
Buy   20 Test MSC for  .00002
TxID: 33644e6f24b29e1ef170d78ff04eab6f7e19368908edc6d477f9902697a71d67

But there is no confirmed payment transaction.   

When buyer posted a sell Transaction (.11 and .9 Test MSC) it is invalid because there was no payment yet for the first transaction.

After reparsing I only found one valid purchase

Buy .2 Test MSC for .003232 BTC
TxID: c7103de53a8ea3a20cec9a74543132f98302f75ab1868092e911dd5516f322a5
Confirm Payment TxID: 2bb54346f7d0ddfcb084451227089665bc1a7ebf8f0a9338d14d713592c268ed


Thanks for checking my data. I'm not sure I understand you correctly though. Could you try explaining it with examples what went wrong?
sr. member
Activity: 284
Merit: 250

Hey Grazcoin,

You'll need to look at your multi-packet handling.  From your de-obfuscated packet It looks like you're SHA hashing the second packet only once.  You'll need to hash seqnum times (so in this case 2).

In terms of a 'definition' for Class B I think the closest thing we have at the mo is my suggested amendment here

Hope that helps Smiley

Grazcoin,

You might want to try convert the first hash to uppercase letters before hashing it again.

hashString1 = the first hash string
ex
Dim HashString2 As String = GetHash(hashString1.ToUpper)

This worked for me.



Thanks guys!
That's exactly what I needed Smiley

sr. member
Activity: 449
Merit: 250

Hey Grazcoin,

You'll need to look at your multi-packet handling.  From your de-obfuscated packet It looks like you're SHA hashing the second packet only once.  You'll need to hash seqnum times (so in this case 2).

In terms of a 'definition' for Class B I think the closest thing we have at the mo is my suggested amendment here

Hope that helps Smiley

Grazcoin,

You might want to try convert the first hash to uppercase letters before hashing it again.

hashString1 = the first hash string
ex
Dim HashString2 As String = GetHash(hashString1.ToUpper)

This worked for me.

sr. member
Activity: 449
Merit: 250
Hi Tachikoma


Buyer 1EdAjiApS5cCpHdH4RKPMab1xmMVRWjLvk posted a
Buy   20 Test MSC for  .00002
TxID: 33644e6f24b29e1ef170d78ff04eab6f7e19368908edc6d477f9902697a71d67

But there is no confirmed payment transaction.   

When buyer posted a sell Transaction (.11 and .9 Test MSC) it is invalid because there was no payment yet for the first transaction.


After reparsing I only found one valid purchase

Buy .2 Test MSC for .003232 BTC
TxID: c7103de53a8ea3a20cec9a74543132f98302f75ab1868092e911dd5516f322a5
Confirm Payment TxID: 2bb54346f7d0ddfcb084451227089665bc1a7ebf8f0a9338d14d713592c268ed





sr. member
Activity: 266
Merit: 250
I am adding now the parsing of sell/buy offers to mastercoin-tools, and I start with this tx:
https://blockchain.info/tx/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34

The first data_hex of the tx, deobfuscated, is:
0001000000140000000200000000773594000000000000004e2006000000000000
and it is parsed to:
[{"tx_hash": "49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34", "block": "267950", "tx_type_str": "Sell offer", "from_address": "13NRX88EZbS5q81x6XFrTECzrciPREo821", "index": "311", "currencyId": "00000002", "tx_time": "1383592863000", "invalid": false, "padding": "000000", "tx_method_str": "multisig", "amount": "0000000077359400", "currency_str": "Test Mastercoin", "formatted_amount": "20.00000000", "to_address": "unknown", "baseCoin": "00", "method": "multisig", "dataSequenceNum": "01", "transactionType": "00000014"}]

This fits to http://mastercoin-explorer.com/transactions/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34
but I still need to decipher the following from the second data_hex:
* Price per coin
* Bitcoin amount desired
* Fee required
* Block time limit

The second data_hex of the tx is:
022eadb2cab02d826df0af54e92a352945c9892df6cd77f1a7c390fc82c8b0edb4

And if I try to deobfuscate it (the same way like the first data_hex), I get:
000966b7aba530122804984859bab666d58150b9d5e5cb007953579259fd7c3000

I still didn't find the format definition anywhere.
Can you please give me a link?

Hey Grazcoin,

You'll need to look at your multi-packet handling.  From your de-obfuscated packet It looks like you're SHA hashing the second packet only once.  You'll need to hash seqnum times (so in this case 2).

In terms of a 'definition' for Class B I think the closest thing we have at the mo is my suggested amendment here

Hope that helps Smiley
sr. member
Activity: 284
Merit: 250
I am adding now the parsing of sell/buy offers to mastercoin-tools, and I start with this tx:
https://blockchain.info/tx/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34

The first data_hex of the tx, deobfuscated, is:
0001000000140000000200000000773594000000000000004e2006000000000000
and it is parsed to:
[{"tx_hash": "49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34", "block": "267950", "tx_type_str": "Sell offer", "from_address": "13NRX88EZbS5q81x6XFrTECzrciPREo821", "index": "311", "currencyId": "00000002", "tx_time": "1383592863000", "invalid": false, "padding": "000000", "tx_method_str": "multisig", "amount": "0000000077359400", "currency_str": "Test Mastercoin", "formatted_amount": "20.00000000", "to_address": "unknown", "baseCoin": "00", "method": "multisig", "dataSequenceNum": "01", "transactionType": "00000014"}]

This fits to http://mastercoin-explorer.com/transactions/49f3efe0eba50ea08220c27d3c8174c5fa8a7782615823ab256859562cbd4a34
but I still need to decipher the following from the second data_hex:
* Price per coin
* Bitcoin amount desired
* Fee required
* Block time limit

The second data_hex of the tx is:
022eadb2cab02d826df0af54e92a352945c9892df6cd77f1a7c390fc82c8b0edb4

And if I try to deobfuscate it (the same way like the first data_hex), I get:
000966b7aba530122804984859bab666d58150b9d5e5cb007953579259fd7c3000

I still didn't find the format definition anywhere.
Can you please give me a link?

sr. member
Activity: 266
Merit: 250
Wow I must be having a stroke  Undecided I was using the total amount of MSC not the reward MSC in my calculation... Thanks for pointing that out! I will get to bed now Smiley

Hehe Smiley you were still doing the right thing (taking 0.1*total_MSC) just getting caught out by that 9th decimal - I'm quite green on Ruby but I think you could correct your original code with .round, so:

Original:
Code:
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.23576222

Suggested:
Code:
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 56316.22357622

Alternate Suggested:
Code:
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * (0.1 * 563_162.23576222).round(8)

Rest easy Smiley
hero member
Activity: 938
Merit: 1000
Wow I must be having a stroke  Undecided I was using the total amount of MSC not the reward MSC in my calculation... Thanks for pointing that out! I will get to bed now Smiley
sr. member
Activity: 266
Merit: 250
It's late and I don't feel too well but I'm still not getting the right result.
Code:
2.0.0p247 :017 >       time_difference = (tx_date.to_i - Mastercoin::END_TIME.to_i) / 60 / 60 / 24 / 365.25
 => 0.16427104722792607
2.0.0p247 :018 >       exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.35762218
 => 6060.79274749

Sorry to hear you're not feeling well, please don't feel at all like you need to respond just take it easy for a bit Smiley

Re above, if you took your original code:

Not sure what changed but I ran the code again now and got a different answer somehow. It's still not a 100% match though.

Code:
1.9.3-p286 :002 > tx_date = Time.parse("2013-10-31 10:45:45 +0100")
 => 2013-10-31 10:45:45 +0100
1.9.3-p286 :003 >   time_difference = (tx_date - Mastercoin::END_TIME) / 60 / 60 / 24 / 365.25
 => 0.1653847250741501
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.23576222
 => 6099.570778312406

And simply change

Code:
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.23576222

to

Code:
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 56316.22357622

You should be set Smiley  Get well soon Smiley
hero member
Activity: 938
Merit: 1000
It maybe a rounding off issue

Zathras
* 56316.23576222

Tachikoma
*.01 * 563162.23576222

Zathras
/31557600

Tachikoma
/ 60 / 60 / 24 / 365.25

Also What is "+0100" in the time
2013-10-31 10:45:45 +0100




Not sure what changed but I ran the code again now and got a different answer somehow. It's still not a 100% match though.

Code:
1.9.3-p286 :002 > tx_date = Time.parse("2013-10-31 10:45:45 +0100")
 => 2013-10-31 10:45:45 +0100
1.9.3-p286 :003 >   time_difference = (tx_date - Mastercoin::END_TIME) / 60 / 60 / 24 / 365.25
 => 0.1653847250741501
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.2357622
 => 6099.570778312406

It's the timezone. I'm guessing that could be the reason for the small difference. I'm betting that if I would recalculate it with an hour difference we get the same numbers. Will check that out as soon as I can.

It's not a timezone issue (we're both using the same value for time difference; 5219145).  The discrepancy is in rounding.  Mastercoins are divisible by 8 decimal places only, thus the reward/dev Mastercoin total is 56316.22357622 (not 56316.223576222).


It's late and I don't feel too well but I'm still not getting the right result.

Code:
2.0.0p247 :017 >       time_difference = (tx_date.to_i - Mastercoin::END_TIME.to_i) / 60 / 60 / 24 / 365.25
 => 0.16427104722792607
2.0.0p247 :018 >       exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.35762218
 => 6060.79274749
sr. member
Activity: 266
Merit: 250
It maybe a rounding off issue

Zathras
* 56316.23576222

Tachikoma
*.01 * 563162.23576222

Zathras
/31557600

Tachikoma
/ 60 / 60 / 24 / 365.25

Also What is "+0100" in the time
2013-10-31 10:45:45 +0100




Not sure what changed but I ran the code again now and got a different answer somehow. It's still not a 100% match though.

Code:
1.9.3-p286 :002 > tx_date = Time.parse("2013-10-31 10:45:45 +0100")
 => 2013-10-31 10:45:45 +0100
1.9.3-p286 :003 >   time_difference = (tx_date - Mastercoin::END_TIME) / 60 / 60 / 24 / 365.25
 => 0.1653847250741501
1.9.3-p286 :004 >  exodus_vesting = (1-(0.5**time_difference)) * 0.1 * 563_162.23576222
 => 6099.570778312406

It's the timezone. I'm guessing that could be the reason for the small difference. I'm betting that if I would recalculate it with an hour difference we get the same numbers. Will check that out as soon as I can.

It's not a timezone issue (we're both using the same value for time difference; 5219145).  The discrepancy is in rounding.  Mastercoins are divisible by 8 decimal places only, thus the reward/dev Mastercoin total is 56316.22357622 (not 56316.223576222).

Your method of using 0.1 * total_purchased_MSC results in a reward/dev MSC total with too many decimal places (9), which thus then produces a slightly skewed vested figure.

For example (again expanded numbers to keep simple)

Code:
Console.WriteLine("Testing against a dev MSC total of 56316.23576222:"
Console.WriteLine((1 - (0.5 ^ ((1383212745 - 1377993600) / 31557600))) * 56316.23576222)

Testing against a dev MSC total of 56316.23576222:
6099.57209816932
Code:
Console.WriteLine("Testing against a dev MSC total of 56316.235762222: (note 9 decimal places)"
Console.WriteLine((1 - (0.5 ^ ((1383212745 - 1377993600) / 31557600))) * 0.1 * 563162.23576222)

Testing against a dev MSC total of 56316.235762222: (note 9 decimal places)
6099.57077831241

I know it's only 0.000000002 but as you can see the second example matches your numbers.  I don't believe that 9th decimal place can be counted hence I believe the correct value (as at 1383212745) was 6099.57209817 MSC - hope this helps Smiley

Code:
Console.WriteLine((1 - (0.5 ^ ((1383212745 - 1377993600) / 31557600))) * 56316.23576222)
6099.57209816932


Sorry should have addressed this to Zathras =)

DateDiff(DateInterval.Second, #1/1/1970#, #9/1/2013#)
= 1377993600
Correct.

DateDiff(DateInterval.Second, #1/1/1970#, #10/01/2013 10:45:45#)
= 1380624345   
Not the same with your result.
=1383212745

How did you get 1383212745 ?
1383212745 is unix time for Tachikoma's original example time (2013-10-31 10:45:45 +0100).  Looks like you have the wrong date in there (10/01/2013).

Thanks! Smiley
legendary
Activity: 1260
Merit: 1031
Rational Exuberance
I was wondering, would it be possible to build upon the same mechanism for BTC-MSC exchange and add support for LTC/other alt-chain exchanging? I don't use LTC or have any but I do know a decent segment would find it useful to be able to trade back and forth between alt currencies. It could be a good, quick, and easy proof-of-concept and validation for Mastercoin to be used to trade other cryptocurrencies around for each other if there was a way to parse/manipulate two blockchains at once.

Actually thinking about it, it probably would be trivial. If you can do it with BTC I don't see why LTC would be difficult but I'm not an expert.

I think once MSC to BTC is working then LTC and the other altcoins ought to be next.


LTC will have to wait until we've got LTC tokens stored in the bitcoin block chain. That will either be user-backed smart property, or escrow-backed tokens later. We can do BTC/MSC now because we are living in the BTC block chain.
hero member
Activity: 714
Merit: 510
I was wondering, would it be possible to build upon the same mechanism for BTC-MSC exchange and add support for LTC/other alt-chain exchanging? I don't use LTC or have any but I do know a decent segment would find it useful to be able to trade back and forth between alt currencies. It could be a good, quick, and easy proof-of-concept and validation for Mastercoin to be used to trade other cryptocurrencies around for each other if there was a way to parse/manipulate two blockchains at once.

Actually thinking about it, it probably would be trivial. If you can do it with BTC I don't see why LTC would be difficult but I'm not an expert.

I think once MSC to BTC is working then LTC and the other altcoins ought to be next.
sr. member
Activity: 449
Merit: 250
legendary
Activity: 1834
Merit: 1019
I was wondering, would it be possible to build upon the same mechanism for BTC-MSC exchange and add support for LTC/other alt-chain exchanging? I don't use LTC or have any but I do know a decent segment would find it useful to be able to trade back and forth between alt currencies. It could be a good, quick, and easy proof-of-concept and validation for Mastercoin to be used to trade other cryptocurrencies around for each other if there was a way to parse/manipulate two blockchains at once.
Pages:
Jump to: