create account

Radiator Update: Getting Ready for Transaction Signing by inertia

View this thread on: hive.blogpeakd.comecency.com
· @inertia · (edited)
$39.23
Radiator Update: Getting Ready for Transaction Signing
Good news!  Radiator got some bug fixes.  Nothing all that important, but I also did a bit of the groundwork needed to support transaction singing.

In this update:

* Logging support, mainly because some annoying messages started showing up from Hashie.
* A quick price feed history lookup.
* A few missing RPC method names.
* Bug fix for when streaming and there are no transactions in the block.  It happens.
* Improved tests.

---

#### Transaction Signing, almost.

Because of [Dan's post](https://steemit.com/steem/@dantheman/steem-and-bitshares-cryptographic-security-update), I have to say, that cleared up a bit of confusion on my part.  It's not like I've been working on this since November, but every time I looked at the code examples, I just didn't know what to make of it.  But now, I think I'm pretty much up to speed.

There's only one problem.  I can't get it to work.  And it's a problem that has been described before, I just need to research it a bit more.

The problem I'm having is, when I build a transaction and broadcast it, I get this message: `tx_missing_posting_auth`

I'm having trouble finding where my mistake is.  I'm aware that if, for instance, you don't format the timestamp correctly, you might get this message.  In fact, it seems like this is what you get when the node can't figure out what you're doing.

But I'm sure it's all on my end.  And I'm sure it's simple.

If you want to take a stab at troubleshooting, I recommend starting here:

https://github.com/inertia186/radiator/blob/master/test/radiator/transaction_test.rb#L22

This test is supposed to mirror what @xeroc documented here:

https://steemit.com/steem/@xeroc/steem-transaction-signing-in-a-nutshell

It does so to the best of my ability, yet the message I get when I run it on a live console is `tx_missing_posting_auth`, like I mentioned.

Anyway, I'll keep troubleshooting.

---

**UPDATE:** Troubleshooting complete.  Radiator is now able to sign transactions.  I just need to make it aware of all operations because for testing purposes, it only supports `vote`.  But here's an example of that:

```ruby
require 'radiator'

transaction = Radiator::Transaction.new(wif: '5JLw5dgQAx6rhZEgNN5C2ds1V47RweGshynFSWFbaMohsYsBvE8')
vote = {
  type: :vote,
  voter: 'xeroc',
  author: 'xeroc',
  permlink: 'piston',
  weight: 10000
}

operation = Radiator::Operation.new(vote)
transaction.operations << operation
transaction.process(true)
```

---

![Radiator](http://www.steemimg.com/images/2016/08/19/RadiatorCoolingFan-54in-Webfdcb1.png)

Related Links:

* Original announcement: [radiator - STEEM Ruby API Client](https://steemit.com/steem/@inertia/radiator-steem-ruby-api-client)
* Previous Update: [Radiator Update: Streaming](https://steemit.com/radiator/@inertia/radiator-update-streaming)
* GitHub: [https://github.com/inertia186/radiator](https://github.com/inertia186/radiator)
* Tags: [#radiator](https://steemit.com/created/radiator), [#ruby](https://steemit.com/created/ruby)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 135 others
👎  
properties (23)
authorinertia
permlinkradiator-update-getting-ready-for-transaction-signing
categoryradiator
json_metadata{"tags":["radiator","ruby","api","steem","update"],"users":["xeroc"],"image":["http://www.steemimg.com/images/2016/08/19/RadiatorCoolingFan-54in-Webfdcb1.png"],"links":["https://steemit.com/steem/@dantheman/steem-and-bitshares-cryptographic-security-update","https://github.com/inertia186/radiator/blob/master/test/radiator/transaction_test.rb#L22","https://steemit.com/steem/@xeroc/steem-transaction-signing-in-a-nutshell","https://steemit.com/steem/@inertia/radiator-steem-ruby-api-client","https://steemit.com/radiator/@inertia/radiator-update-streaming","https://github.com/inertia186/radiator","https://steemit.com/created/radiator","https://steemit.com/created/ruby"],"app":"steemit/0.1","format":"markdown"}
created2017-02-25 06:55:00
last_update2017-02-25 21:24:24
depth0
children12
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value38.194 HBD
curator_payout_value1.034 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,992
author_reputation346,568,901,399,561
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id2,588,850
net_rshares46,242,426,607,611
author_curate_reward""
vote details (200)
@ripplerm ·
> tx_missing_posting_auth  

the message state that your txn doesn't had the correct signature.
either you signed it with wrong a key, or there's a problem with your signing algorithm.
properties (22)
authorripplerm
permlinkre-inertia-radiator-update-getting-ready-for-transaction-signing-20170225t191905762z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2017-02-25 19:19:03
last_update2017-02-25 19:19:03
depth1
children0
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length184
author_reputation12,900,481,895,884
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,592,309
net_rshares0
@ripplerm ·
$0.10
I'm not familiar with ruby... 

am i understand correctly that the tx.expiration keep changing on each loop of signature generation? 
```
      loop do
        @expiration += 1
        sig = ec.sign_compact(digest_hex, @private_key.priv, public_key_hex)
        
        next if public_key_hex != ec.recover_compact(digest_hex, sig)
        
        return sig if canonical? sig
      end
```
https://github.com/inertia186/radiator/blob/master/lib/radiator/transaction.rb#L102
👍  , , , ,
properties (23)
authorripplerm
permlinkre-inertia-radiator-update-getting-ready-for-transaction-signing-20170226t083423245z
categoryradiator
json_metadata{"tags":["radiator"],"links":["https://github.com/inertia186/radiator/blob/master/lib/radiator/transaction.rb#L102"],"app":"steemit/0.1"}
created2017-02-26 08:34:21
last_update2017-02-26 08:34:21
depth1
children3
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.094 HBD
curator_payout_value0.010 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length476
author_reputation12,900,481,895,884
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,596,044
net_rshares231,208,294,745
author_curate_reward""
vote details (5)
@inertia ·
Correct.  It adds a second for each generation attempt.  That's probably way too much time to add, but it hasn't been an issue.

Graphenej does this too, but they only add 1 millisecond per iteration.  I should probably do the same.

https://github.com/kenCode-de/graphenej/blob/master/graphenej/src/main/java/de/bitsharesmunich/graphenej/Transaction.java#L145
👍  
properties (23)
authorinertia
permlinkre-ripplerm-re-inertia-radiator-update-getting-ready-for-transaction-signing-20170226t084107309z
categoryradiator
json_metadata{"tags":["radiator"],"links":["https://github.com/kenCode-de/graphenej/blob/master/graphenej/src/main/java/de/bitsharesmunich/graphenej/Transaction.java#L145"],"app":"steemit/0.1"}
created2017-02-26 08:41:06
last_update2017-02-26 08:41:06
depth2
children2
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length360
author_reputation346,568,901,399,561
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,596,078
net_rshares13,938,126,173
author_curate_reward""
vote details (1)
@ripplerm ·
this step is redundant IMO....

but it's okay if the users are aware of it. 
- he can't set a fixed expiration, 
- tx_id can't be determined until signing done.
properties (22)
authorripplerm
permlinkre-inertia-re-ripplerm-re-inertia-radiator-update-getting-ready-for-transaction-signing-20170226t090410051z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2017-02-26 09:04:09
last_update2017-02-26 09:04:09
depth3
children1
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length160
author_reputation12,900,481,895,884
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,596,164
net_rshares0
@sneak ·
Perhaps create the same signed tx with steem.js and radiator and diff them?

Example failed txes/code here in comments might allow some community members to help out.
👍  , , , , ,
properties (23)
authorsneak
permlinkre-inertia-radiator-update-getting-ready-for-transaction-signing-20170225t092837064z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2017-02-25 09:28:36
last_update2017-02-25 09:28:36
depth1
children4
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length166
author_reputation28,694,344,106,492
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,589,267
net_rshares233,910,741,949
author_curate_reward""
vote details (6)
@inertia ·
Yep, good point.  I should probably make sure the digest hash is the same in `steem.js` just before it signs.  To that end, here's the ruby code to set up the initial conditions:

```ruby
      options = {
        wif: '5JLw5dgQAx6rhZEgNN5C2ds1V47RweGshynFSWFbaMohsYsBvE8',
        ref_block_num: 36029,
        ref_block_prefix: 1164960351,
        expiration: Time.parse('2016-08-08T12:24:17 Z'),
      }
      
      @transaction = Radiator::Transaction.new(options)
```

I'm using the wif and block data @xeroc uses in his examples so the serialization matches, which it does.  Normally, from the console, these things and the timestamp are based on what the blockchain says + 30 seconds.  I tried 15 seconds just now, no-go.  The purpose of this comment is to make sure the digest (hash) is correct.

Anyway, this creates the transaction data:

```ruby
      vote = {
        type: :vote,
        voter: 'xeroc',
        author: 'xeroc',
        permlink: 'piston',
        weight: 10000
      }
      
      operation = Radiator::Operation.new(vote)
      
      @transaction.operations << operation
      refute_nil bytes = @transaction.send(:to_bytes)
```

Which creates a serialization:

```
0000000000000000000000000000000000000000000000000000000000000000BD8C5FE26F45F179A8570100057865726F63057865726F6306706973746F6E102700
```

And a corresponding hash (aka digest via `Digest::SHA256.digest` in ruby) that is ready to sign:

```
582176B1DAF89984BC8B4FDCB24FF1433D1EB114A8C4BF20FB22AD580D035889
```

Note, I hexlified the final hash here so I can post it for reference.  *Normally*, the hash is signed without the hexilfy step.
properties (22)
authorinertia
permlinkre-sneak-re-inertia-radiator-update-getting-ready-for-transaction-signing-20170225t095956230z
categoryradiator
json_metadata{"tags":["radiator"],"users":["xeroc"],"app":"steemit/0.1"}
created2017-02-25 09:59:57
last_update2017-02-25 09:59:57
depth2
children3
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,638
author_reputation346,568,901,399,561
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,589,357
net_rshares0
@inertia ·
Ok, turns out, I was generating a bad digest.  I'm still looking at specifically why.  I can generate the correct digest for the previous example:

```
ccbcb7d64444356654febe83b8010ca50d99edd0389d273b63746ecaf21adb92
```

In addition to switching to lower case hexlified output (which only affects debugging), I also had to trim the input, but that's not really the fix because it's binary.  I need a better way to tell when the bytes being hashed are being sent with extra, erroneous byte.

---

When it outputs the correct digest, there's still a problem, but it's progress!  The response I get changed from `tx_missing_posting_auth` to `assert_exception`:

```
Assert Exception
  trx.ref_block_prefix == tapos_block_summary.block_id._hash[1]:
    {"trx.ref_block_prefix":1717647203,"tapos_block_summary":2083887546}
      th_a  database.cpp:3281 _apply_transaction
```
properties (22)
authorinertia
permlinkre-inertia-re-sneak-re-inertia-radiator-update-getting-ready-for-transaction-signing-20170225t190822252z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2017-02-25 19:08:21
last_update2017-02-25 19:08:21
depth3
children2
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length871
author_reputation346,568,901,399,561
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,592,218
net_rshares0
@transisto ·
$0.11
I'm trying to kickstart the use of a new tag, #steemdev, your content should use that tag. I'll pretty much upvote anything that is legit steem related dev content posted with that tag and downvote what's not.
👍  , , , ,
properties (23)
authortransisto
permlinkre-inertia-radiator-update-getting-ready-for-transaction-signing-20170226t223312107z
categoryradiator
json_metadata{"tags":["steemdev","radiator"],"app":"steemit/0.1"}
created2017-02-26 22:33:09
last_update2017-02-26 22:33:09
depth1
children1
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.106 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length209
author_reputation330,357,940,720,833
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,600,674
net_rshares235,476,063,573
author_curate_reward""
vote details (5)
@abit ·
Good to know.
properties (22)
authorabit
permlinkre-transisto-re-inertia-radiator-update-getting-ready-for-transaction-signing-20170228t183100809z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2017-02-28 18:31:51
last_update2017-02-28 18:31:51
depth2
children0
last_payout2017-03-28 08:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length13
author_reputation141,171,499,037,785
root_title"Radiator Update: Getting Ready for Transaction Signing"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,614,703
net_rshares0