github.com/loomnetwork/gamechain@v0.0.0-20200406110549-36c47eb97a92/README.md (about) 1 # Zombie Battleground 2 3 ## Build Zombie Battleground Contract 4 5 ``` 6 make deps 7 make 8 ``` 9 10 ## Oracle 11 12 Generate a set of private and public keys by entering the following command: 13 14 ``` 15 loom genkey -k oracle-priv.key -a oracle-pub.key > oracle-key.txt 16 ``` 17 18 List the content of `oracle-key.txt` with `cat oracle-key.txt`. You should see something like this printed out to the console: 19 20 ```bash 21 local address: 0x97A3F939B6d14fD9C0E037963d18Bb37A9B9c646 22 local address base64: l6P5ObbRT9nA4DeWPRi7N6m5xkY= 23 ``` 24 25 Copy base64 address and paste it into the "oracle" section of the `genesis.json` file: 26 27 ``` 28 "oracle": { 29 "chainId": "default", 30 "local": <PASTE_HERE_THE_ORACLE_KEY> 31 ``` 32 33 Note that, on a chain that's already running, you can update the address of the oracle with the following command: 34 35 ```bash 36 ./bin/zb-cli update_oracle default:NEW_ORACLE_ADDRESS default:CURRENT_ORACLE_ADDRESS -k oracle.priv 37 ``` 38 39 ## Run with loomchain 40 41 Make sure you have [loom](github.com/loomnetwork/loomchain) binary. 42 43 Run the follwing commands in the `gamechain` directory: 44 ``` 45 loom init 46 cp zb.genesis.json genesis.json 47 loom run 48 ``` 49 50 ## Creating account and running transactions 51 52 Create a keypair by entering: 53 54 ``` 55 loom genkey -k <username>-priv.key -a <username>-pub.key 56 # Note that setAccount and getAccount supports all fields defined in `UpsertAccountRequest`. To make example simple, 57 # only two fields has been used. 58 ``` 59 60 > Don't forget to replace <username> with your username. 61 62 Create the account: 63 64 ``` 65 ./bin/zb-cli create_account -k <username>-priv.key -u <username> -v v25 -d "{\"image\":\"Image\", \"game_membership_tier\": 1}" 66 ``` 67 68 Verify if the account was created: 69 70 ``` 71 ./bin/zb-cli get_account -k <username>-priv.key -u <username> 72 ``` 73 74 Other useful commands (not required for spinning up the game): 75 76 ``` 77 # update account transaction 78 ./bin/zb-cli update_account -k <username>-priv.key -u <username> -v "{\"image\":\"Image2\", \"game_membership_tier\": 2}" 79 80 # Get Decks 81 ./bin/zb-cli get_decks -k <username>-priv.key -u <username> -v v1 82 83 # Get Deck by id 84 ./bin/zb-cli get_deck -k <username>-priv.key -u <username> --deckId 0 85 86 # Add Deck 87 ./bin/zb-cli create_deck -k <username>-priv.key -u <username> -v v2 -d "{\"overlordId\":\"1\", \"name\": \"NewDeck\", \"cards\": [ {\"card_name\": \"Banshee\", \"amount\": 2}, {\"card_name\": \"Breezee\", \"amount\": 1} ]}" 88 89 # Delete Deck by id 90 ./bin/zb-cli delete_deck -k <username>-priv.key -u <username> --deckId 0 -v v1 91 ``` 92 93 # Initial setup 94 95 Contract must be initialized with correct data to work properly. 96 97 1. Set the PlasmaChain block number from which the oracle will fetch the events: 98 99 ```bash 100 ./bin/zb-cli set_last_plasma_block_number -n 3066893 # for staging plasmachain, update accordingly otherwise 101 ``` 102 103 2. Set contract configuration 104 105 ```bash 106 ./bin/zb-cli -k oracle-priv.key contract_configuration set_fiat_purchase_contract_version -v 3 # update if contract version changes 107 ./bin/zb-cli -k oracle-priv.key contract_configuration set_initial_fiat_purchase_txid -v 85070591730234615865843651858142052964 # for dev, shift the start accordingly to the last used txid 108 ./bin/zb-cli -k oracle-priv.key contract_configuration set_card_collection_sync_data_version -v v25 # data version to use for card sync, update accordingly to the current data version 109 ``` 110 111 ## TxId Start 112 113 IAP purchases handled by Auth have TxId incrementing from 0, and can't be reused. Since Gamechain can't communicate with Auth, the solution is to split the ranges used by Auth and Gamechain for TxId. 114 115 ### Production 116 117 Starts from (2^127 + 10000) = 170141183460469231731687303715884115728 118 Ends on (2^256 - 1) 119 120 ### Staging 121 122 Starts from (2^126 + 100000000) = 85070591730234615865843651858042052864 123 Ends on (2^126 + 200000000) 124 125 ### Development 126 127 Starts from (2^126 + 200000000) = 85070591730234615865843651858142052864 128 Ends on (2^126 + 300000000) 129 130 ### Local Development 131 132 Starts from (2^126) = 85070591730234615865843651857942052864 133 Ends on (2^126 + 100000000 - 1) 134 135 ## Update initial data 136 137 When new initial data such as cards, overlords, or decks, needs to be updated, run the following command: 138 139 ```bash 140 ./bin/zb-cli -k oracle-priv.key update_init -f update_init_v26.json 141 ```