-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,050 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
*************************************************** | ||
Howto Monitor the blockchain for certain operations | ||
*************************************************** | ||
|
||
Operations in blocks can be monitored relatively easy by using the | ||
`block_stream` (for entire blocks) for `stream` (for specific | ||
operations) generators. | ||
|
||
The following example will only show ``transfer`` operations on the | ||
blockchain: | ||
|
||
.. code-block:: python | ||
from grapheneapi.grapheneclient import GrapheneClient | ||
from pprint import pprint | ||
class Config(): | ||
witness_url = "ws://testnet.bitshares.eu/ws" | ||
if __name__ == '__main__': | ||
client = GrapheneClient(Config) | ||
for b in client.ws.stream("transfer"): | ||
pprint(b) | ||
Note that you can define a starting block and instead of waiting for | ||
sufficient confirmations (irreversible blocks), you can also consider | ||
the real *head* block with: | ||
|
||
.. code-block:: python | ||
for b in client.ws.stream("transfer", start=199924, mode="head"): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from grapheneapi.grapheneclient import GrapheneClient | ||
from pprint import pprint | ||
|
||
|
||
class config(): | ||
witness_url = "ws://testnet.bitshares.eu/ws" | ||
wallet_host = "localhost" | ||
wallet_port = 8092 | ||
|
||
|
||
if __name__ == '__main__': | ||
client = GrapheneClient(config) | ||
graphene = client.rpc | ||
|
||
# Get current fees | ||
core_asset = graphene.get_asset("1.3.0") | ||
committee_account = graphene.get_account("committee-account") | ||
proposals = client.ws.get_proposed_transactions(committee_account["id"]) | ||
|
||
for proposal in proposals: | ||
print("Proposal: %s" % proposal["id"]) | ||
|
||
prop_op = proposal["proposed_transaction"]["operations"] | ||
|
||
if len(prop_op) > 1: | ||
print(" - [Warning] This proposal has more than 1 operation") | ||
|
||
if graphene._confirm("Approve?"): | ||
tx = graphene.approve_proposal( | ||
"xeroc", | ||
proposal["id"], | ||
{"active_approvals_to_add": | ||
["committee-member-1", | ||
"committee-member-2", | ||
"committee-member-3", | ||
"committee-member-4", | ||
"committee-member-5", | ||
"committee-member-6", | ||
"committee-member-7", | ||
"init0", | ||
"init1", | ||
"init2", | ||
"init3", | ||
]}, | ||
True) | ||
pprint(tx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from grapheneapi.grapheneclient import GrapheneClient | ||
from graphenebase.transactions import getOperationNameForId | ||
from pprint import pprint | ||
from deepdiff import DeepDiff | ||
|
||
proposer = "xeroc" | ||
expiration = "2016-05-17T09:00:00" | ||
price_per_kbyte = 0 | ||
everythin_flat_fee = 0.001 | ||
broadcast = True | ||
|
||
|
||
class Wallet(): | ||
wallet_host = "localhost" | ||
wallet_port = 8092 | ||
|
||
if __name__ == '__main__': | ||
graphene = GrapheneClient(Wallet) | ||
obj = graphene.getObject("2.0.0") | ||
current_fees = obj["parameters"]["current_fees"]["parameters"] | ||
old_fees = obj["parameters"]["current_fees"] | ||
scale = obj["parameters"]["current_fees"]["scale"] / 1e4 | ||
|
||
# General change of parameter | ||
changes = {} | ||
for f in current_fees: | ||
if ("price_per_kbyte" in f[1] and f[1]["price_per_kbyte"] != 0): | ||
print("Changing operation %s[%d]" % (getOperationNameForId( | ||
f[0]), f[0])) | ||
changes[getOperationNameForId(f[0])] = f[1].copy() | ||
changes[getOperationNameForId(f[0])]["price_per_kbyte"] = int( | ||
price_per_kbyte / scale * 1e5) | ||
if ("fee" in f[1] and f[1]["fee"] != 0): | ||
print("Changing operation %s[%d]" % (getOperationNameForId( | ||
f[0]), f[0])) | ||
changes[getOperationNameForId(f[0])] = f[1].copy() | ||
changes[getOperationNameForId(f[0])]["fee"] = int( | ||
everythin_flat_fee / scale * 1e5) | ||
|
||
# overwrite / set specific fees | ||
changes["transfer"]["price_per_kbyte"] = int(0) | ||
# changes["account_update"]["price_per_kbyte"] = int( 5 / scale * 1e5) | ||
|
||
print("=" * 80) | ||
tx = graphene.rpc.propose_fee_change(proposer, | ||
expiration, | ||
changes, | ||
broadcast) | ||
proposed_ops = tx["operations"][0][1]["proposed_ops"][0] | ||
new_fees = proposed_ops["op"][1]["new_parameters"]["current_fees"] | ||
|
||
pprint(DeepDiff(old_fees, new_fees)) | ||
|
||
if not broadcast: | ||
print("=" * 80) | ||
print("Set broadcast to 'True' if the transaction shall be broadcast!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from grapheneapi import GrapheneClient | ||
from grapheneexchange import GrapheneExchange | ||
from graphenebase import transactions | ||
from pprint import pprint | ||
|
||
issuer = "xeroc" | ||
from_account = "maker" | ||
to_account = "xeroc" | ||
asset = "LIVE" | ||
amount = 100.0 | ||
wifs = ["<active-wif-key-of-issuer>"] | ||
witness_url = "ws://testnet.bitshares.eu/ws" | ||
|
||
|
||
def constructSignedTransaction(ops): | ||
ops = transactions.addRequiredFees(client.ws, ops, "1.3.0") | ||
ref_block_num, ref_block_prefix = transactions.getBlockParams(client.ws) | ||
expiration = transactions.formatTimeFromNow(30) | ||
tx = transactions.Signed_Transaction( | ||
ref_block_num=ref_block_num, | ||
ref_block_prefix=ref_block_prefix, | ||
expiration=expiration, | ||
operations=ops | ||
) | ||
w = tx.sign(wifs, chain=client.getChainInfo()) | ||
return w | ||
|
||
|
||
#: Connetion Settings | ||
class Config(): | ||
witness_url = witness_url | ||
|
||
|
||
if __name__ == '__main__': | ||
config = Config | ||
client = GrapheneClient(config) | ||
|
||
issuer = client.ws.get_account(issuer) | ||
from_account = client.ws.get_account(from_account) | ||
to_account = client.ws.get_account(to_account) | ||
asset = client.ws.get_asset(asset) | ||
amount = int(amount * 10 ** asset["precision"]) | ||
|
||
ops = [] | ||
op = transactions.Override_transfer(**{ | ||
"fee": {"amount": 0, | ||
"asset_id": "1.3.0"}, | ||
"issuer": issuer["id"], | ||
"from": from_account["id"], | ||
"to": to_account["id"], | ||
"amount": {"amount": amount, | ||
"asset_id": asset["id"]}, | ||
"extensions": [] | ||
}) | ||
ops.append(transactions.Operation(op)) | ||
|
||
tx = constructSignedTransaction(ops) | ||
pprint(transactions.JsonObj(tx)) | ||
print(client.ws.broadcast_transaction(transactions.JsonObj(tx), api="network_broadcast")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.