richardblythman commited on
Commit
eb33e84
·
1 Parent(s): f8ec69f

add alg token balance

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -8,7 +8,7 @@ from ocean_lib.web3_internal.currency import from_wei # wei is the smallest deno
8
  config = Config('config.ini')
9
  ocean = Ocean(config)
10
 
11
- def wallet(private_key):
12
  wallet = Wallet(ocean.web3, private_key, transaction_timeout=20, block_confirmations=config.block_confirmations)
13
  address = wallet.address
14
  OCEAN_token = BToken(ocean.web3, ocean.OCEAN_address)
@@ -16,30 +16,51 @@ def wallet(private_key):
16
  eth_balance = from_wei(ocean.web3.eth.get_balance(wallet.address))
17
  ocean_balance = from_wei(OCEAN_token.balanceOf(wallet.address))
18
 
19
- return address, eth_balance, ocean_balance
 
 
 
 
 
 
 
20
 
21
  description = (
22
- "This demo calculate the number of tokens in your wallet on the Rinkeby test network using the Ocean Python library. \n"
23
- "You can export your private key from your metamask wallet. We highly recommend doing this with a wallet that has no real tokens in it (only Rinkeby tokens)."
24
- "For more info on private keys, see [this](https://github.com/oceanprotocol/ocean.py/blob/main/READMEs/wallets.md) from the ocean.py documentation"
 
 
 
 
 
 
 
25
  )
26
 
27
  article = (
28
  "<p style='text-align: center'>"
29
- "<a href='https://oceanprotocol.com/' target='_blank'>Ocean Protocol</a> | "
 
30
  "<a href='https://github.com/oceanprotocol/ocean.py' target='_blank'>Ocean Python Library</a> | "
31
- "<a href='https://www.algovera.ai' target='_blank'>Algovera</a>"
 
 
32
  "</p>"
33
  )
34
 
35
 
36
  interface = gr.Interface(
37
  wallet,
38
- "text",
 
 
 
39
  [
40
  gr.outputs.Textbox(label="Public Key"),
41
  gr.outputs.Textbox(label="ETH balance"),
42
  gr.outputs.Textbox(label="OCEAN balance"),
 
43
  ],
44
  title="Ocean Token Calculator",
45
  description=description,
 
8
  config = Config('config.ini')
9
  ocean = Ocean(config)
10
 
11
+ def wallet(private_key, did):
12
  wallet = Wallet(ocean.web3, private_key, transaction_timeout=20, block_confirmations=config.block_confirmations)
13
  address = wallet.address
14
  OCEAN_token = BToken(ocean.web3, ocean.OCEAN_address)
 
16
  eth_balance = from_wei(ocean.web3.eth.get_balance(wallet.address))
17
  ocean_balance = from_wei(OCEAN_token.balanceOf(wallet.address))
18
 
19
+ asset = ocean.assets.resolve(did)
20
+
21
+ ALG_ddo = ocean.assets.resolve(did)
22
+ alg_token = ocean.get_data_token(ALG_ddo.data_token_address)
23
+
24
+ alg_token_balance = pretty_ether_and_wei(alg_token.balanceOf(wallet.address)
25
+
26
+ return address, eth_balance, ocean_balance, alg_token_balance
27
 
28
  description = (
29
+ "The Ocean marketplace allows you to publish and sell algorithms and datasets in exchange for crypto tokens. "
30
+ "This demo counts the number of ETH and OCEAN tokens in your wallet for a given private key. It uses a test network (Rinkeby) where the tokens have no real value. "
31
+ "You can export your private key from your MetaMask wallet. We highly recommend doing this with a wallet that has no real tokens in it (only test tokens). "
32
+ "For a guide on how to install MetaMask wallet (an extension in your browser), check the link at the bottom of the page. "
33
+ "Initially, your wallet should have no tokens. You can request ETH and OCEAN test tokens from faucets at the links at the bottom of the page. "
34
+ "You can also count the number of algorithm tokens in your wallet for an algorithm that you specify. "
35
+ "To buy an algorithm token, you can search for algorithms on the Ocean marketplace (see link at bottom). Make sure to use algorithms that are on the Rinkeby test network (you need to select Rinkeby from the dropdown menu). "
36
+ "We have provided a link to our DCGAN model on the test network at the bottom. If you can't see it you are not on the test network. "
37
+ "After you buy an algorithm token, you need to locate the DID in the metadata on the marketplace. Then enter it into the input textbox. "
38
+ "Later we will add HF spaces apps to search algorithms and buy algorithm tokens, which you can use to run demos of the algorithms."
39
  )
40
 
41
  article = (
42
  "<p style='text-align: center'>"
43
+ "<a href='https://market.oceanprotocol.com/' target='_blank'>Ocean marketplace</a> | "
44
+ "<a href='https://market.oceanprotocol.com/asset/did:op:E2e123115d5758Dd4C6F434E1c142e72ed8B2820' target='_blank'>DCGAN algorithm</a> | "
45
  "<a href='https://github.com/oceanprotocol/ocean.py' target='_blank'>Ocean Python Library</a> | "
46
+ "<a href='https://docs.oceanprotocol.com/tutorials/metamask-setup/' target='_blank'>Guide for installing MetaMask</a> | "
47
+ "<a href='https://faucet.rinkeby.io/' target='_blank'>ETH faucet</a> | "
48
+ "<a href='https://faucet.rinkeby.oceanprotocol.com/' target='_blank'>OCEAN faucet</a> | "
49
  "</p>"
50
  )
51
 
52
 
53
  interface = gr.Interface(
54
  wallet,
55
+ [
56
+ gr.inputs.Textbox(label="Private Key"),
57
+ gr.inputs.Textbox(placeholder="did:op:E2e123115d5758Dd4C6F434E1c142e72ed8B2820", label="Algorithm DID"),
58
+ ],
59
  [
60
  gr.outputs.Textbox(label="Public Key"),
61
  gr.outputs.Textbox(label="ETH balance"),
62
  gr.outputs.Textbox(label="OCEAN balance"),
63
+ gr.outputs.Textbox(label="Algorithm token balance"),
64
  ],
65
  title="Ocean Token Calculator",
66
  description=description,