create account

HIVE-ads project: (first) Weekly progress report by mattockfs

View this thread on: hive.blogpeakd.comecency.com
· @mattockfs ·
$11.39
HIVE-ads project: (first) Weekly progress report
![image.png](https://files.peakd.com/file/peakd-hive/mattockfs/J0RXbDKl-image.png)

In this post I want to share my modest progress on the new Hive-Adds project. Hive-Ads is to be a rethink and reboot of the old abandoned @steemsense-eu, and a pilot project to explore the use of [FlureeDB](https://flur.ee/) as a HIVE sidechain.

For an idea of what is coming, check out the [post](/hive-139531/@mattockfs/feedback-wanted-an-updated-outline-for-a-add-revenues-ecconomy-for-the-hive-platform-using-flureedb) I did last week, trying to gauge if I should do this project. Thanks everybody for the positive feedback on that post. 

I'm not going to rehash the basic setup, I'll do other posts on that when I reach important milestones, in this/these posts I only want to share the progress on the project to keep interested people in the loop.

## DTAP

The first important note for this project is, I don't intend to eventually run the code of this project myself. I'm a data and code guy, not really a system administration person. I'll be focusing on the D(evelopment), (T)esting and (A)cceptance, not (P)roduction. Not just because I'm really not an admin, but also because of the trust model the code will rely on. HIVE has a trust web that I as a non-witness aren't part of. A system like the one envisioned should eventually be run by a high reputation witness, and that's not me.

For the T+A part of the development DTAP project setup I'll be using three HIVE accounts. My old @pibarabot account that I'm powering up and repurposing as main HIVE-ads T+A bot account, the newly created @pibarabank account that is meant to manage batched financial transactions, and in the near future, a third account meant to manage FlureeDB side-chain synchronization.

The progress here this week has been:
* Created @pibarabank account
* Started powering up @pibarabot and @pibarabank
* Found out (see below in the side-chain section) I need a third bot account.

## Github projects

Not much there yet, but I've created a set of github repos for the project.

* [hive-ads](https://github.com/pibara/hive-ads)
* [hive-sidechain-flureedb](https://github.com/pibara/hive-sidechain-flureedb)
* [hive-ads-flureedb-schema](https://github.com/pibara/hive-ads-flureedb-schema)
* [hive-ads-bot](https://github.com/pibara/hive-ads-bot)
* [hive-ads-bank](https://github.com/pibara/hive-ads-bank)

The *hive-sidechain-flureedb* is meant to be a lazy synchronizer between HIVE and the FlureeDB database that I'm using for the project. More about that below. The *hive-ads-flureedb-schema* repo is meant for importing the hive-adds domain model and the access-rights to this model into FlureeDB. The *hive-ads-bot* repo is meant for the main bot code. The *hive-ads-bank* script is meant to be the code that takes care of pending pay-outs, refunds and burns.

## Looked into escrow

Took some time to look into the HIVE escrow API and if I could map my hive-ads-bank needs to it. Seems, at least for now,  it won't be of much help. As the idea for a bank-like account, the only possible way right now to implement the system, is sub-optimal, even if a *trusted* witness will end up running the system eventually, I'm thinking about writing up an outline. 

Think the ideal system would look something like this.

1) The hive-ads creates a deposit template, defining:
   * 25% of the split should go to null (burn)
   * 75% of split should be split according to the split as specified by the ad system
   * A timeout of 40 days for funds to be refunded to the campaign owner.
   * A dispute timeout of 4 days.
   * An arbiter

2) The campaign owner does an escrow-like transfer, specifying the template above.
3) Every week the ad system creates a split-proposal specifying:
   * Any immediate refund (no arbitrage needed)
   * The amount to be split between content creators and @null
   * The division of split between content-creators.

4) If the campaign owner doesn't open a dispute, the split proposal is honored.
5) If the campaign owner opens a dispute that the arbiter can resolve.

At this moment I'm just putting this out there as a HIVE feature that I think could prove really useful for projects like mine, and I'm keeping focus on my own project.

## hive-sidechain-flureedb experiments

So far I've been experimenting with some scripts for the hive-sidechain-flureedb sub-project. One of the goals of the hive-ads project is to become a pilot for the use of FlureeDB for a side-chain. FlureeDB is a triple-store graph-database that runs on top of blockchain technology. 

One of the primary functions needed for FlureeDB to run as a side-chain to HIVE is synchonizing the users from HIVE into the Fluree database. FlureeDB comes with a quite powerfull access control system for its data. FlureeDB uses data centric security, and by defining roles, rules and smart functions, a side chain App like hive-ads can implement basically any access control rule needed for implementation. A first step though to make that possible is filling the FlureeDB with HIVE users and key-id's as used by FlureeDB.

FlureeDB and HIVE make use of pretty much compatible crypto. And as the HIVE *get_account* API call returns the ECDSA public keys of the account, we can construct FlureeDB key id's. 

The way we do that is, we use the Python bitcoinlib library to turn the HIVE pubkeys into bitcoin adresses.

![image.png](https://files.peakd.com/file/peakd-hive/mattockfs/zsY0CI8o-image.png)

We can than decompose the bitcoin adress, replace the bitcoin 0x00 prefix with the FlureeDB \x0f\x02 and calculate an updated checksum like this:

```python
def hive_pubkey_to_fluree_address(ownerpubkey):
    pubkeyb58 = ownerpubkey[3:]
    pubkey = base58.b58decode(pubkeyb58)[:-4]
    bitcoin_pubkey = bitcoinlib.keys.Key(pubkey)
    bitcoin_address = bitcoin_pubkey.address()
    core = b'\x0f\x02' + base58.b58decode(bitcoin_address)[1:-4]
    h1 = hashlib.sha256()
    h2 = hashlib.sha256()
    h1.update(core)
    h2.update(h1.digest())
    keyid = base58.b58encode(core + h2.digest()[:4]).decode()
    return keyid
```

Now in my experiment, I use this code from a script that reads all new blocks, extracts all references to accounts, does a *get_accounts* API call for any account it hasn't seen yet or any account mentioned in an *account_update* or *recover_account* operation. 

This is how far I've come this week. Next step is to stream this data into FlureeDB so that every active account on HIVE eventually ends up in the FlureeDB side-chain. In fact, it wouldn't be a side-chain if we wouldn't do this.

## Next?

Next steps coming up now is the creations of basic roles, rules and possibly smart functions needed for access control with the different rules. If there are roles in the FlureeDB schema, I can start turning my experiment into a synchronizer. I'll power up the two existing accounts a bit more and will create a third one for the side-chain synchronizer.

My next post will hopefully be about a working side-chain-synchronizer. 

Like before, all input on my project is highly welcomed. 
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authormattockfs
permlinkhive-ads-project-first-weekly-progress-report
categoryhive-139531
json_metadata"{"app":"peakd/2020.11.1","format":"markdown","description":"HIVE-Ads progress report including accounts/github setup, reading up on escrow & little FlureeDB side-chain experiment.","portfolio":true,"tags":["hivedevs","hive-ads","hive","flureedb","sidechain","ads","development","hivesense"],"users":["steemsense-eu","mattockfs","pibarabot","pibarabank","null"],"links":["/@steemsense-eu","https://flur.ee/","/hive-139531/@mattockfs/feedback-wanted-an-updated-outline-for-a-add-revenues-ecconomy-for-the-hive-platform-using-flureedb","/@pibarabot","/@pibarabank","/@pibarabank","/@pibarabot","/@pibarabank","https://github.com/pibara/hive-ads","https://github.com/pibara/hive-sidechain-flureedb"],"image":["https://files.peakd.com/file/peakd-hive/mattockfs/J0RXbDKl-image.png","https://files.peakd.com/file/peakd-hive/mattockfs/zsY0CI8o-image.png"]}"
created2020-11-19 13:29:00
last_update2020-11-19 13:29:00
depth0
children6
last_payout2020-11-26 13:29:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value11.393 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,087
author_reputation11,180,453,239,559
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries
0.
accountcroupierbot
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id100,596,766
net_rshares89,355,685,465,851
author_curate_reward""
vote details (57)
@aggroed ·
$0.04
Can you come find me in discord or through something like the nftshowroom.com chat?  I'm interested in learning more RE: hive-Engine and using something like this for tribes.
👍  , , ,
properties (23)
authoraggroed
permlinkre-mattockfs-qk9gmn
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.11.1"}
created2020-11-23 17:59:12
last_update2020-11-23 17:59:12
depth1
children0
last_payout2020-11-30 17:59:12
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.022 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length174
author_reputation1,258,335,829,240,616
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,652,568
net_rshares365,461,278,306
author_curate_reward""
vote details (4)
@lyubo19 ·
$0.04
I just read this post (as well as this [one](https://peakd.com/hive-139531/@mattockfs/feedback-wanted-an-updated-outline-for-a-add-revenues-ecconomy-for-the-hive-platform-using-flureedb) ) and I'm very proud that people like you are developing the Hive networks.
My admirations!
👍  , , ,
properties (23)
authorlyubo19
permlinkre-mattockfs-qk9c40
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.11.1"}
created2020-11-23 16:21:36
last_update2020-11-23 16:21:36
depth1
children0
last_payout2020-11-30 16:21:36
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.022 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length279
author_reputation46,588,534,247,858
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,651,386
net_rshares358,155,537,528
author_curate_reward""
vote details (4)
@poshbot ·
$0.04
https://twitter.com/EngineerDiet/status/1329422454406713346
👍  , , , ,
properties (23)
authorposhbot
permlinkre-hive-ads-project-first-weekly-progress-report-20201119t135315z
categoryhive-139531
json_metadata"{"app": "beem/0.24.8"}"
created2020-11-19 13:53:15
last_update2020-11-19 13:53:15
depth1
children0
last_payout2020-11-26 13:53:15
cashout_time1969-12-31 23:59:59
total_payout_value0.021 HBD
curator_payout_value0.021 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length59
author_reputation5,554,335,374,496
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,597,031
net_rshares316,072,107,807
author_curate_reward""
vote details (5)
@poshbot ·
https://twitter.com/EngineerDiet/status/1329949028860256256
properties (22)
authorposhbot
permlinkre-hive-ads-project-first-weekly-progress-report-20201121t004626z
categoryhive-139531
json_metadata"{"app": "beem/0.24.8"}"
created2020-11-21 00:46:27
last_update2020-11-21 00:46:27
depth1
children0
last_payout2020-11-28 00:46:27
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_length59
author_reputation5,554,335,374,496
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,617,119
net_rshares0
@poshbot ·
https://twitter.com/PowerGames8/status/1330178584795869186
properties (22)
authorposhbot
permlinkre-hive-ads-project-first-weekly-progress-report-20201121t155838z
categoryhive-139531
json_metadata"{"app": "beem/0.24.8"}"
created2020-11-21 15:58:39
last_update2020-11-21 15:58:39
depth1
children0
last_payout2020-11-28 15:58:39
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_length58
author_reputation5,554,335,374,496
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,624,200
net_rshares0
@urun ·
$0.04
very techy :)

How it would look like at the end from the mechanic point?

👍  , , ,
properties (23)
authorurun
permlinkre-mattockfs-qk5mpj
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.11.1"}
created2020-11-21 16:20:09
last_update2020-11-21 16:20:09
depth1
children0
last_payout2020-11-28 16:20:09
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.022 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length75
author_reputation93,309,389,073,611
root_title"HIVE-ads project: (first) Weekly progress report "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,624,482
net_rshares351,000,206,050
author_curate_reward""
vote details (4)