Skip to content

Commit

Permalink
[Price Feed Script] Rename Witness->Producer; Allow non witnesses to …
Browse files Browse the repository at this point in the history
…produce price; Allow to produce price for only secondary assets
  • Loading branch information
xeroc committed Jan 25, 2016
1 parent 82db904 commit 96db203
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions scripts/pricefeeds/config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
ask_confirmation = True # if true, a manual confirmation is required

################################################################################
## Witness Feed Publish Parameters
## Feed Producer Name
################################################################################
witness_name = "init0"
producer_name = "init0"

################################################################################
## Publishing Criteria
Expand Down
33 changes: 23 additions & 10 deletions scripts/pricefeeds/pricefeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## ##
## This is EXPERIMENTAL code!! ##
## ##
## If you are a witness capable of publishing a price feed for ##
## If you are a feed producer capable of publishing a price feed for ##
## market pegged assets, you should carefully REVIEW this code in order to ##
## not publish a wrong price that may ##
## ##
Expand Down Expand Up @@ -92,10 +92,17 @@ def fetch_from_wallet(rpc):
"""
print("Fetching data from wallet...")

# Get my Witness
global myWitness
myWitness = rpc.get_witness(config.witness_name)
witnessId = myWitness["witness_account"]
# Get feed producer
global myWitness, producerAccount
try:
# try if witness name is actually a witness:
myWitness = rpc.get_witness(config.producer_name)
producerID = myWitness["witness_account"]
producerAccount = rpc.get_account(producerID)
except:
producerAccount = rpc.get_account(config.producer_name)
producerID = producerAccount["id"]
pass

# asset definition - mainly for precision
for asset in asset_list_publish + ["1.3.0"]:
Expand Down Expand Up @@ -125,7 +132,7 @@ def fetch_from_wallet(rpc):

# my feed specifics
for feed in result["feeds"] :
if feed[0] == witnessId :
if feed[0] == producerID :
lastUpdate[asset] = datetime.strptime(feed[1][0], "%Y-%m-%dT%H:%M:%S")
base = feed[1][1]["settlement_price"]["base"]
quote = feed[1][1]["settlement_price"]["quote"]
Expand All @@ -148,23 +155,23 @@ def update_feed(rpc, feeds):
print("Unlocking wallet")
rpc.unlock(config.unlock)

print("constructing feed for witness %s" % config.witness_name)
print("constructing feed for producer %s" % config.producer_name)
handle = rpc.begin_builder_transaction()
for asset in feeds :
if not feeds[asset]["publish"] :
continue
op = [19, # id 19 corresponds to price feed update operation
{"asset_id" : feeds[asset]["asset_id"],
"feed" : feeds[asset]["feed"],
"publisher" : myWitness["witness_account"],
"publisher" : producerAccount["id"],
}]
rpc.add_operation_to_builder_transaction(handle, op)

# Set fee
rpc.set_fees_on_builder_transaction(handle, "1.3.0")

# Signing and Broadcast
rpc.sign_builder_transaction(handle, True)
rpc.sign_builder_transaction(handle, False)

if wallet_was_unlocked :
print("Relocking wallet")
Expand All @@ -178,7 +185,13 @@ def derive_prices(feed):
for asset in _all_bts_assets + [core_symbol]:
price_result[asset] = {}

for asset in asset_list_publish :
# secondary assets requirements
secondaries = []
for asset in config.secondary_mpas.keys():
if "sameas" in config.secondary_mpas[asset]:
secondaries.append(config.secondary_mpas[asset]["sameas"])

for asset in asset_list_publish + secondaries:
# secondary markets are different
if asset in list(config.secondary_mpas.keys()) :
continue
Expand Down

0 comments on commit 96db203

Please sign in to comment.