Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
fix as comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattharat Wiriyakulnan committed Aug 25, 2020
1 parent 615b324 commit 5b279b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 42 deletions.
4 changes: 2 additions & 2 deletions chain/emitter/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func (app *App) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
var oracleState oracle.GenesisState
app.Codec().MustUnmarshalJSON(genesisState[oracle.ModuleName], &oracleState)
for idx, ds := range oracleState.DataSources {
app.emitNewDataSource(types.DataSourceID(idx+1), ds, nil)
app.emitSetDataSource(types.DataSourceID(idx+1), ds, nil)
}
for idx, os := range oracleState.OracleScripts {
app.emitNewOracleScript(types.OracleScriptID(idx+1), os, nil)
app.emitSetOracleScript(types.OracleScriptID(idx+1), os, nil)
}
app.FlushMessages()
return res
Expand Down
28 changes: 2 additions & 26 deletions chain/emitter/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ func parseBytes(b []byte) []byte {
return b
}

func (app *App) emitNewDataSource(id types.DataSourceID, ds types.DataSource, txHash []byte) {
app.Write("NEW_DATA_SOURCE", JsDict{
"id": id,
"name": ds.Name,
"description": ds.Description,
"owner": ds.Owner.String(),
"executable": app.OracleKeeper.GetFile(ds.Filename),
"tx_hash": txHash,
})
}

func (app *App) emitSetDataSource(id types.DataSourceID, ds types.DataSource, txHash []byte) {
app.Write("SET_DATA_SOURCE", JsDict{
"id": id,
Expand All @@ -36,19 +25,6 @@ func (app *App) emitSetDataSource(id types.DataSourceID, ds types.DataSource, tx
})
}

func (app *App) emitNewOracleScript(id types.OracleScriptID, os types.OracleScript, txHash []byte) {
app.Write("NEW_ORACLE_SCRIPT", JsDict{
"id": id,
"name": os.Name,
"description": os.Description,
"owner": os.Owner.String(),
"schema": os.Schema,
"codehash": os.Filename,
"source_code_url": os.SourceCodeURL,
"tx_hash": txHash,
})
}

func (app *App) emitSetOracleScript(id types.OracleScriptID, os types.OracleScript, txHash []byte) {
app.Write("SET_ORACLE_SCRIPT", JsDict{
"id": id,
Expand Down Expand Up @@ -136,7 +112,7 @@ func (app *App) handleMsgCreateDataSource(
) {
id := types.DataSourceID(atoi(evMap[types.EventTypeCreateDataSource+"."+types.AttributeKeyID][0]))
ds := app.BandApp.OracleKeeper.MustGetDataSource(app.DeliverContext, id)
app.emitNewDataSource(id, ds, txHash)
app.emitSetDataSource(id, ds, txHash)
extra["id"] = id
}

Expand All @@ -146,7 +122,7 @@ func (app *App) handleMsgCreateOracleScript(
) {
id := types.OracleScriptID(atoi(evMap[types.EventTypeCreateOracleScript+"."+types.AttributeKeyID][0]))
os := app.BandApp.OracleKeeper.MustGetOracleScript(app.DeliverContext, id)
app.emitNewOracleScript(id, os, txHash)
app.emitSetOracleScript(id, os, txHash)
extra["id"] = id
}

Expand Down
24 changes: 10 additions & 14 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ def handle_set_account(self, msg):
condition = (col == msg[col.name]) & condition
self.conn.execute(accounts.update().where(condition).values(**msg))

def handle_new_data_source(self, msg):
self.handle_set_data_source(msg)
self.handle_new_data_source_request({"data_source_id": msg["id"], "count": 0})

def handle_set_data_source(self, msg):
if msg["tx_hash"] is not None:
msg["transaction_id"] = self.get_transaction_id(msg["tx_hash"])
Expand All @@ -95,10 +91,11 @@ def handle_set_data_source(self, msg):
.values(**msg)
.on_conflict_do_update(constraint="data_sources_pkey", set_=msg)
)

def handle_new_oracle_script(self, msg):
self.handle_set_oracle_script(msg)
self.handle_new_oracle_script_request({"oracle_script_id": msg["id"], "count": 0})
self.conn.execute(
insert(data_source_requests)
.values({"data_source_id": msg["id"], "count": 0})
.on_conflict_do_nothing(constraint="data_source_requests_pkey")
)

def handle_set_oracle_script(self, msg):
if msg["tx_hash"] is not None:
Expand All @@ -111,6 +108,11 @@ def handle_set_oracle_script(self, msg):
.values(**msg)
.on_conflict_do_update(constraint="oracle_scripts_pkey", set_=msg)
)
self.conn.execute(
insert(oracle_script_requests)
.values({"oracle_script_id": msg["id"], "count": 0})
.on_conflict_do_nothing(constraint="oracle_script_requests_pkey")
)

def handle_new_request(self, msg):
msg["transaction_id"] = self.get_transaction_id(msg["tx_hash"])
Expand Down Expand Up @@ -315,9 +317,6 @@ def handle_set_historical_validator_status(self, msg):
.on_conflict_do_update(constraint="historical_oracle_statuses_pkey", set_=msg)
)

def handle_new_data_source_request(self, msg):
self.conn.execute(data_source_requests.insert(), msg)

def handle_set_data_source_request(self, msg):
condition = True
for col in data_source_requests.primary_key.columns.values():
Expand All @@ -326,9 +325,6 @@ def handle_set_data_source_request(self, msg):
data_source_requests.update(condition).values(count=data_source_requests.c.count + 1)
)

def handle_new_oracle_script_request(self, msg):
self.conn.execute(oracle_script_requests.insert(), msg)

def handle_set_oracle_script_request(self, msg):
condition = True
for col in oracle_script_requests.primary_key.columns.values():
Expand Down

0 comments on commit 5b279b6

Please sign in to comment.