Skip to content

Commit

Permalink
sends preflight transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
scottburch committed Feb 13, 2021
1 parent e4c89f3 commit 2bcf6db
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func NewCRUDApp(
supply.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, crud.StoreKey,
tax.StoreKey,
faucet.StoreKey, crud.LeaseKey, crud.OwnerKey)
faucet.StoreKey, crud.LeaseKey, crud.OwnerKey, oracle.StoreKey)

tkeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)

Expand Down Expand Up @@ -318,6 +318,7 @@ func NewCRUDApp(
tax.ModuleName,
supply.ModuleName,
genutil.ModuleName,
oracle.ModuleName,
)

// register all module routes and module queriers
Expand All @@ -343,7 +344,8 @@ func NewCRUDApp(
tmos.Exit(err.Error())
}

oracle.StartFeeder(app.crudKeeper, app.accountKeeper, *cdc)
// TODO: I added this delay for testing purposes. Remove and see what happens after it is working
defer oracle.StartFeeder(app.crudKeeper, app.accountKeeper, *cdc)

return app
}
Expand Down
46 changes: 24 additions & 22 deletions x/oracle/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ var logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))


var oracleUser = struct{
address string
pubkey string
//address string
//pubkey string
mnemonic string
}{
address: "bluzelle1ws42h2gjr6q8u5d2teexhrzz9xr9lqrxru50u2",
pubkey: "bluzellepub1addwnpepq0yg97vrptalxxwy6rykm85jdeam9eqcgy0v3s0reuzcsvsekzakgp8d7mc",
//address: "bluzelle1ws42h2gjr6q8u5d2teexhrzz9xr9lqrxru50u2",
//pubkey: "bluzellepub1addwnpepq0yg97vrptalxxwy6rykm85jdeam9eqcgy0v3s0reuzcsvsekzakgp8d7mc",
mnemonic: "bone soup garage safe hotel remove rebuild tumble usage marriage skin opinion banana scene focus obtain very soap vocal print symptom winter update hundred",
}


type source struct {
type Source struct {
Name string
Url string `json:"url"`
Property string `json:"property"`
Expand Down Expand Up @@ -83,7 +83,7 @@ func feederTick(crudKeeper crud.Keeper) {


for _, v := range keyValues {
source := source{}
source := Source{}
json.Unmarshal([]byte(decodeSafe(v.Value)), &source)
source.Name = v.Key

Expand All @@ -92,30 +92,33 @@ func feederTick(crudKeeper crud.Keeper) {
if err == nil {
sendPreflightMsg(source, value)
} else {
logger.Info("Feeder: unable to fetch from source " + "(" + source.Url + ")" + err.Error())
logger.Info("Feeder: unable to fetch from Source " + "(" + source.Url + ")" + err.Error())
}

}
}

func sendPreflightMsg(source source, value float64) {
func sendPreflightMsg(source Source, value float64) {
keybase := clientKeys.NewInMemoryKeyBase()
account, err := keybase.CreateAccount("oracle", oracleUser.mnemonic, cryptoKeys.DefaultBIP39Passphrase, clientKeys.DefaultKeyPass, "44'/118'/0'/0/0", cryptoKeys.Secp256k1)

if(err != nil) {
logger.Info("Error creating keybase account", err)
}

valConsAdd := getValconsAddress()

proofStr := fmt.Sprintf("%s%f", valConsAdd, value)
proof := []byte(proofStr)
sum := sha256.Sum256(proof)
msg := types.NewMsgOracleVoteProof(valConsAdd, string(sum[:]))
err := msg.ValidateBasic()
msgs := []sdk.Msg{msg}

owner, _ := sdk.AccAddressFromBech32("bluzelle1ws42h2gjr6q8u5d2teexhrzz9xr9lqrxru50u2")
msg := types.NewMsgOracleVoteProof(valConsAdd, string(sum[:]), owner)
err = msg.ValidateBasic()

if err == nil {
keybase := clientKeys.NewInMemoryKeyBase()
info, err := keybase.CreateAccount("oracle", oracleUser.mnemonic, cryptoKeys.DefaultBIP39Passphrase, clientKeys.DefaultKeyPass, "44'/118'/0'/0/0", cryptoKeys.Secp256k1)
if(err != nil) {
logger.Info("Error creating keybase account", err)
}
address := info.GetAddress()
msgs := []sdk.Msg{msg}

address := account.GetAddress()
acc := accountKeeper.GetAccount(*currCtx, address)

// TODO: make sure to dynamically get the chainID
Expand All @@ -128,14 +131,13 @@ func sendPreflightMsg(source source, value float64) {
signedMsg, err := txBldr.BuildAndSign("oracle", clientKeys.DefaultKeyPass, msgs)
if err == nil {
rpcCtx := rpctypes.Context{}
bres, err := core.BroadcastTxSync(&rpcCtx, signedMsg)
fmt.Println(bres)
fmt.Println(err)
core.BroadcastTxCommit(&rpcCtx, signedMsg)
}

}
}

func fetchFromSource(source source) (float64, error) {
func fetchFromSource(source Source) (float64, error) {
client := resty.New()

resp, err := client.R().
Expand Down
1 change: 1 addition & 0 deletions x/oracle/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// handle<Action> does x

func handleMsgOracleVoteProof(ctx sdk.Context, k keeper.Keeper, msg types.MsgOracleVoteProof) (*sdk.Result, error) {
fmt.Printf("HERE")
//err := k.OracleVoteProof(ctx, msg.ValidatorAddr)
//if err != nil {
// return nil, err
Expand Down
6 changes: 4 additions & 2 deletions x/oracle/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ var _ sdk.Msg = &MsgOracleVoteProof{}
type MsgOracleVoteProof struct {
ValidatorAddr string `json:"address"` // address of the validator operator
VoteHash string `json:"voteHash"`
Owner sdk.AccAddress `json:"owner"`
}


// NewMsgOracleVoteProof creates a new MsgOracleVoteProof instance

func NewMsgOracleVoteProof(validatorAddr string, voteHash string) MsgOracleVoteProof {
func NewMsgOracleVoteProof(validatorAddr string, voteHash string, owner sdk.AccAddress) MsgOracleVoteProof {
return MsgOracleVoteProof{
ValidatorAddr: validatorAddr,
VoteHash: voteHash,
Owner: owner,
}
}

Expand All @@ -34,7 +36,7 @@ func NewMsgOracleVoteProof(validatorAddr string, voteHash string) MsgOracleVoteP
func (msg MsgOracleVoteProof) Route() string { return RouterKey }
func (msg MsgOracleVoteProof) Type() string { return OracleVoteProofConst }
func (msg MsgOracleVoteProof) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddr)}
return []sdk.AccAddress{sdk.AccAddress(msg.Owner)}
}

// GetSignBytes gets the bytes for the message signer to sign on
Expand Down

0 comments on commit 2bcf6db

Please sign in to comment.