Skip to content

Add Msg Scripts #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8de7532
Create MsgCreateDataSource.py
SurpriseMF3000 Feb 16, 2022
92802ec
Create MsgEditDataSource.py
SurpriseMF3000 Feb 16, 2022
a6bb3cd
MsgCreateDataSource.py
SurpriseMF3000 Feb 16, 2022
e7074cd
MsgEditDataSource.py
SurpriseMF3000 Feb 16, 2022
b02626a
MsgCreateOracleScript.py
SurpriseMF3000 Feb 16, 2022
789ab5d
.\MsgEditOracleScript.py
SurpriseMF3000 Feb 17, 2022
40fd0b0
MsgEditOracleScript.py
SurpriseMF3000 Feb 17, 2022
d9c7147
MsgEditOracleScript.py
SurpriseMF3000 Feb 17, 2022
1592a31
MsgRequestData.py
SurpriseMF3000 Feb 17, 2022
63b730e
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
6b7db02
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
7a11373
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
4ce5dcd
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
d60081c
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
22b0499
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
20b5233
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
f407226
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
7ba22f5
Msg Readme.md
SurpriseMF3000 Feb 17, 2022
5cdd854
Delete Readme.md
SurpriseMF3000 Feb 17, 2022
9156255
Update Readme.md
SurpriseMF3000 Feb 17, 2022
8c9d6f0
Merge branch 'master' of https://github.com/SurpriseMF3000/pyband
SurpriseMF3000 Feb 17, 2022
65c5f50
Msg README.md
SurpriseMF3000 Feb 17, 2022
f3a3c38
MsgEditDataSource.py
SurpriseMF3000 Feb 17, 2022
26f97ca
MsgEditOracleScript.py
SurpriseMF3000 Feb 17, 2022
975a4d3
MsgRequestData.py
SurpriseMF3000 Feb 17, 2022
e7fee95
Delete old scripts
SurpriseMF3000 Feb 17, 2022
53412bd
MsgCreateDataSource,py
SurpriseMF3000 Feb 17, 2022
1d954e4
MsgCreateOracleScript.py
SurpriseMF3000 Feb 17, 2022
ff25383
MsgEditDataSource.py
SurpriseMF3000 Feb 17, 2022
2960b54
MsgEditOracleScript.py
SurpriseMF3000 Feb 17, 2022
fbdbd85
MsgRequestData.py
SurpriseMF3000 Feb 17, 2022
06acc17
README.md
SurpriseMF3000 Feb 17, 2022
8ce5a65
README.md
SurpriseMF3000 Feb 17, 2022
4138ddb
README.md
SurpriseMF3000 Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions pyband/msg scripts/MsgCreateDataSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os

from pyband.client import Client
from pyband.transaction import Transaction
from pyband.wallet import PrivateKey

from pyband.proto.cosmos.base.v1beta1.coin_pb2 import Coin
from pyband.proto.oracle.v1.tx_pb2 import MsgCreateDataSource
from google.protobuf.json_format import MessageToJson

def main():
# Step 1
#Choose GRPC
#Laozi Mainnet: laozi1.bandchain.org
#Laozi Testnet: laozi-testnet4.bandchain.org
grpc_url = "laozi1.bandchain.org"
c = Client(grpc_url)

# Step 2
#DO NOT SHARE YOUR mnemonic!!!
private_key = PrivateKey.from_mnemonic("Enter your mnemonic (Seed Phrases)")
public_key = private_key.to_public_key()
sender_addr = public_key.to_address()
sender = sender_addr.to_acc_bech32()

# Step 3
send_msg = MsgCreateDataSource(
sender=sender,
owner = "Band Address of the Owner",
treasury = "Band Address of the Treasury",
name = "Name of the Data Source",
description = "Description of the Data Source",
fee = [Coin(amount="Fee per single request", denom="uband")], #1000000 Uband is one Band
executable = b' Paste your Code (Executable) in here \n', #the b'\n' converts your code into []Byte
)

account = c.get_account(sender)
account_num = account.account_number
sequence = account.sequence

chain_id = c.get_chain_id()

# Step 4
txn = (
Transaction()
.with_messages(send_msg)
.with_sequence(sequence)
.with_account_num(account_num)
.with_chain_id(chain_id)
.with_gas(2000000)
.with_memo("")
)

# Step 5
sign_doc = txn.get_sign_doc(public_key)
signature = private_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = txn.get_tx_data(signature, public_key)

# Step 6
tx_block = c.send_tx_block_mode(tx_raw_bytes)
print(MessageToJson(tx_block))

if __name__ == "__main__":
main()
63 changes: 63 additions & 0 deletions pyband/msg scripts/MsgCreateOracleScript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os

from pyband.client import Client
from pyband.transaction import Transaction
from pyband.wallet import PrivateKey

from pyband.proto.oracle.v1.tx_pb2 import MsgCreateOracleScript
from google.protobuf.json_format import MessageToJson

def main():
# Step 1
#Choose GRPC
#Laozi Mainnet: laozi1.bandchain.org
#Laozi Testnet: laozi-testnet4.bandchain.org
grpc_url = "laozi-testnet4.bandchain.org"
c = Client(grpc_url)

# Step 2
#DO NOT SHARE YOUR mnemonic!!!
private_key = PrivateKey.from_mnemonic("Enter your mnemonic (Seed Phrases)")
public_key = private_key.to_public_key()
sender_addr = public_key.to_address()
sender = sender_addr.to_acc_bech32()

# Step 3
send_msg = MsgCreateOracleScript(
sender=sender,
owner = "Band Address of the Owner",
name = "Name of the Oracle Script",
description = "Description of the Oracle Script",
code = b' The Owasm-compiled binary attached to this Oracle Script \n', #the b'\n' converts your code into Byte
schema= "The schema detailing the inputs and outputs of this Oracle Script, as well as the corresponding types",
source_code_url="Url of the Source Code",
)

account = c.get_account(sender)
account_num = account.account_number
sequence = account.sequence

chain_id = c.get_chain_id()

# Step 4
txn = (
Transaction()
.with_messages(send_msg)
.with_sequence(sequence)
.with_account_num(account_num)
.with_chain_id(chain_id)
.with_gas(2000000)
.with_memo("")
)

# Step 5
sign_doc = txn.get_sign_doc(public_key)
signature = private_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = txn.get_tx_data(signature, public_key)

# Step 6
tx_block = c.send_tx_block_mode(tx_raw_bytes)
print(MessageToJson(tx_block))

if __name__ == "__main__":
main()
68 changes: 68 additions & 0 deletions pyband/msg scripts/MsgEditDataSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os

from pyband.client import Client
from pyband.transaction import Transaction
from pyband.wallet import PrivateKey

from pyband.proto.cosmos.base.v1beta1.coin_pb2 import Coin
from pyband.proto.oracle.v1.tx_pb2 import MsgEditDataSource
from google.protobuf.json_format import MessageToJson

def main():
# Step 1
#Choose GRPC
#Laozi Mainnet: laozi1.bandchain.org
#Laozi Testnet: laozi-testnet4.bandchain.org
grpc_url = "laozi-testnet4.bandchain.org"
c = Client(grpc_url)

# Step 2
#DO NOT SHARE YOUR mnemonic!!!
private_key = PrivateKey.from_mnemonic("Enter your mnemonic (Seed Phrases)")
public_key = private_key.to_public_key()
sender_addr = public_key.to_address()
sender = sender_addr.to_acc_bech32()

# Step 3
send_msg = MsgEditDataSource(
data_source_id="Data Source ID from your existing Data Source without Quotation Marks (int)",
sender=sender,
#now you can change your existingData Source completely
owner = "Band Address of the Owner",
treasury = "Band Address of the Treasury",
name = "Name of the Data Source",
description = "Description of the Data Source",
fee = [Coin(amount="Fee per single request", denom="uband")], #1000000 Uband is one Band
executable = b' Paste your Code (Executable) in here \n', #the b'\n' converts your code into Byte
)

account = c.get_account(sender)
account_num = account.account_number
sequence = account.sequence

fee = [Coin(amount="10000", denom="uband")]
chain_id = c.get_chain_id()

# Step 4
txn = (
Transaction()
.with_messages(send_msg)
.with_sequence(sequence)
.with_account_num(account_num)
.with_chain_id(chain_id)
.with_gas(2000000)
.with_fee(fee)
.with_memo("")
)

# Step 5
sign_doc = txn.get_sign_doc(public_key)
signature = private_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = txn.get_tx_data(signature, public_key)

# Step 6
tx_block = c.send_tx_block_mode(tx_raw_bytes)
print(MessageToJson(tx_block))

if __name__ == "__main__":
main()
64 changes: 64 additions & 0 deletions pyband/msg scripts/MsgEditOracleScript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os

from pyband.client import Client
from pyband.transaction import Transaction
from pyband.wallet import PrivateKey

from pyband.proto.oracle.v1.tx_pb2 import MsgEditOracleScript
from google.protobuf.json_format import MessageToJson

def main():
# Step 1
#Choose GRPC
#Laozi Mainnet: laozi1.bandchain.org
#Laozi Testnet: laozi-testnet4.bandchain.org
grpc_url = "laozi-testnet4.bandchain.org"
c = Client(grpc_url)

# Step 2
#DO NOT SHARE YOUR mnemonic!!!
private_key = PrivateKey.from_mnemonic("Enter your mnemonic (Seed Phrases)")
public_key = private_key.to_public_key()
sender_addr = public_key.to_address()
sender = sender_addr.to_acc_bech32()

# Step 3
send_msg = MsgEditOracleScript(
oracle_script_id="Oracle Script ID from your existing Data Source without Quotation Marks (int)",
sender=sender,
owner = "Band Address of the Owner",
name = "Name of the Oracle Script",
description = "Description of the Oracle Script",
code = b' The Owasm-compiled binary attached to this Oracle Script \n', #the b'\n' converts your code into Byte
schema= "The schema detailing the inputs and outputs of this Oracle Script, as well as the corresponding types",
source_code_url="Url of the Source Code",
)

account = c.get_account(sender)
account_num = account.account_number
sequence = account.sequence

chain_id = c.get_chain_id()

# Step 4
txn = (
Transaction()
.with_messages(send_msg)
.with_sequence(sequence)
.with_account_num(account_num)
.with_chain_id(chain_id)
.with_gas(2000000)
.with_memo("")
)

# Step 5
sign_doc = txn.get_sign_doc(public_key)
signature = private_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = txn.get_tx_data(signature, public_key)

# Step 6
tx_block = c.send_tx_block_mode(tx_raw_bytes)
print(MessageToJson(tx_block))

if __name__ == "__main__":
main()
65 changes: 65 additions & 0 deletions pyband/msg scripts/MsgRequestData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os

from pyband.client import Client
from pyband.transaction import Transaction
from pyband.wallet import PrivateKey

from pyband.proto.cosmos.base.v1beta1.coin_pb2 import Coin
from pyband.proto.oracle.v1.tx_pb2 import MsgRequestData
from google.protobuf.json_format import MessageToJson

def main():
# Step 1
#Choose GRPC
#Laozi Mainnet: laozi1.bandchain.org
#Laozi Testnet: laozi-testnet4.bandchain.org
grpc_url = "laozi-testnet4.bandchain.org"
c = Client(grpc_url)

# Step 2
#DO NOT SHARE YOUR mnemonic!!!
private_key = PrivateKey.from_mnemonic("Enter your mnemonic (Seed Phrases)")
public_key = private_key.to_public_key()
sender_addr = public_key.to_address()
sender = sender_addr.to_acc_bech32()

# Step 3
send_msg = MsgRequestData(
oracle_script_id = "Oracle Script ID from any existing Oracle you wish to get Data from without Quotation Marks (int)",
sender = sender,
calldata = "The data passed over to the oracle script for the script to use during its execution (string)",
ask_count = "Number of validators requested to answer the request without Quotation Marks (int)",
min_count = "The minimum number of validators necessary for the request to proceed to the execution phase without Quotation Marks (int)",
client_id = "The unique identifier of this oracle request, as specified by the client. This same unique ID will be sent back to the requester with the oracle response (string)",
)

account = c.get_account(sender)
account_num = account.account_number
sequence = account.sequence

fee = [Coin(amount="10000", denom="uband")]
chain_id = c.get_chain_id()

# Step 4
txn = (
Transaction()
.with_messages(send_msg)
.with_sequence(sequence)
.with_account_num(account_num)
.with_chain_id(chain_id)
.with_gas(2000000)
.with_fee(fee)
.with_memo("")
)

# Step 5
sign_doc = txn.get_sign_doc(public_key)
signature = private_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = txn.get_tx_data(signature, public_key)

# Step 6
tx_block = c.send_tx_block_mode(tx_raw_bytes)
print(MessageToJson(tx_block))

if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions pyband/msg scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Band Protocol pyband Msg Scripts

1. MsgRequestData.py to Request Data

2. MsgCreateDataSource.py to create a new Data Source
3. MsgEditDataSource.py to edit an existing Data Source

4. MsgCreateOracleScript.py to create a new Oracle Script
5. MsgEditOracleScript.py to edit an existing Oracle Script



If you have any questions:

https://docs.bandchain.org/

https://docs.bandchain.org/whitepaper/protocol-messages.html