Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ###############################################################################
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) typedef int GmbH
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. ###############################################################################
  26. import os
  27. import json
  28. import binascii
  29. import pkg_resources
  30. os.environ['ETH_HASH_BACKEND'] = 'pycryptodome'
  31. # from eth_hash.backends.pycryptodome import keccak256 # noqa
  32. # print('Using eth_hash backend {}'.format(keccak256))
  33. import web3
  34. import xbr
  35. XBR_ABI_VERSION = xbr.__version__
  36. """
  37. XBR Protocol contracts ABI bundle (Python package) version.
  38. """
  39. #
  40. # Set default XBR contract addresses to
  41. # XBR v20.5.1. @ Rinkeby (https://github.com/crossbario/xbr-protocol/issues/127)
  42. #
  43. if 'XBR_DEBUG_TOKEN_ADDR' in os.environ:
  44. _token_adr = os.environ['XBR_DEBUG_TOKEN_ADDR']
  45. try:
  46. _token_adr = binascii.a2b_hex(_token_adr[2:])
  47. _token_adr = web3.Web3.toChecksumAddress(_token_adr)
  48. except Exception as e:
  49. raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_TOKEN_ADDR={} - {}'.format(_token_adr, e))
  50. XBR_DEBUG_TOKEN_ADDR = _token_adr
  51. XBR_DEBUG_TOKEN_ADDR_SRC = 'envvar $XBR_DEBUG_TOKEN_ADDR'
  52. else:
  53. XBR_DEBUG_TOKEN_ADDR = '0xaCef957D54c639575f4DB68b1992B36504f33FEA'
  54. XBR_DEBUG_TOKEN_ADDR_SRC = 'builtin'
  55. if 'XBR_DEBUG_NETWORK_ADDR' in os.environ:
  56. _netw_adr = os.environ['XBR_DEBUG_NETWORK_ADDR']
  57. try:
  58. _netw_adr = binascii.a2b_hex(_netw_adr[2:])
  59. _netw_adr = web3.Web3.toChecksumAddress(_netw_adr)
  60. except Exception as e:
  61. raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_NETWORK_ADDR={} - {}'.format(_netw_adr, e))
  62. XBR_DEBUG_NETWORK_ADDR = _netw_adr
  63. XBR_DEBUG_NETWORK_ADDR_SRC = 'envvar $XBR_DEBUG_NETWORK_ADDR'
  64. else:
  65. XBR_DEBUG_NETWORK_ADDR = '0x7A3d22c59e8F8f1b88ba7205f3f5a65Bc86D04Bc'
  66. XBR_DEBUG_NETWORK_ADDR_SRC = 'builtin'
  67. if 'XBR_DEBUG_DOMAIN_ADDR' in os.environ:
  68. _domain_adr = os.environ['XBR_DEBUG_DOMAIN_ADDR']
  69. try:
  70. _domain_adr = binascii.a2b_hex(_domain_adr[2:])
  71. _domain_adr = web3.Web3.toChecksumAddress(_domain_adr)
  72. except Exception as e:
  73. raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_DOMAIN_ADDR={} - {}'.format(_domain_adr, e))
  74. XBR_DEBUG_DOMAIN_ADDR = _domain_adr
  75. XBR_DEBUG_DOMAIN_ADDR_SRC = 'envvar $XBR_DEBUG_DOMAIN_ADDR'
  76. else:
  77. XBR_DEBUG_DOMAIN_ADDR = '0xf5fb56886f033855C1a36F651E927551749361bC'
  78. XBR_DEBUG_DOMAIN_ADDR_SRC = 'builtin'
  79. if 'XBR_DEBUG_CATALOG_ADDR' in os.environ:
  80. _ctlg_adr = os.environ['XBR_DEBUG_CATALOG_ADDR']
  81. try:
  82. _ctlg_adr = binascii.a2b_hex(_ctlg_adr[2:])
  83. _ctlg_adr = web3.Web3.toChecksumAddress(_ctlg_adr)
  84. except Exception as e:
  85. raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_CATALOG_ADDR={} - {}'.format(_ctlg_adr, e))
  86. XBR_DEBUG_CATALOG_ADDR = _ctlg_adr
  87. XBR_DEBUG_CATALOG_ADDR_SRC = 'envvar $XBR_DEBUG_CATALOG_ADDR'
  88. else:
  89. XBR_DEBUG_CATALOG_ADDR = '0x2C77E46Ea9502B363343e8c826c41c7fdb25Db66'
  90. XBR_DEBUG_CATALOG_ADDR_SRC = 'builtin'
  91. if 'XBR_DEBUG_MARKET_ADDR' in os.environ:
  92. _mrkt_adr = os.environ['XBR_DEBUG_MARKET_ADDR']
  93. try:
  94. _mrkt_adr = binascii.a2b_hex(_mrkt_adr[2:])
  95. _mrkt_adr = web3.Web3.toChecksumAddress(_mrkt_adr)
  96. except Exception as e:
  97. raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_MARKET_ADDR={} - {}'.format(_mrkt_adr, e))
  98. XBR_DEBUG_MARKET_ADDR = _mrkt_adr
  99. XBR_DEBUG_MARKET_ADDR_SRC = 'envvar $XBR_DEBUG_MARKET_ADDR'
  100. else:
  101. XBR_DEBUG_MARKET_ADDR = '0x0DcF924ab0846101d31514E9fb3adf5070d4B83d'
  102. XBR_DEBUG_MARKET_ADDR_SRC = 'builtin'
  103. if 'XBR_DEBUG_CHANNEL_ADDR' in os.environ:
  104. _chnl_adr = os.environ['XBR_DEBUG_CHANNEL_ADDR']
  105. try:
  106. _chnl_adr = binascii.a2b_hex(_chnl_adr[2:])
  107. _chnl_adr = web3.Web3.toChecksumAddress(_chnl_adr)
  108. except Exception as e:
  109. raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_CHANNEL_ADDR={} - {}'.format(_chnl_adr, e))
  110. XBR_DEBUG_CHANNEL_ADDR = _chnl_adr
  111. XBR_DEBUG_CHANNEL_ADDR_SRC = 'envvar $XBR_DEBUG_CHANNEL_ADDR'
  112. else:
  113. XBR_DEBUG_CHANNEL_ADDR = '0x670497A012322B99a5C18B8463940996141Cb952'
  114. XBR_DEBUG_CHANNEL_ADDR_SRC = 'builtin'
  115. def _load_json(contract_name):
  116. fn = pkg_resources.resource_filename('xbr', 'abi/{}.json'.format(contract_name))
  117. with open(fn) as f:
  118. data = json.loads(f.read())
  119. return data
  120. #
  121. # XBR contract ABI file names
  122. #
  123. XBR_TOKEN_FN = pkg_resources.resource_filename('xbr', 'abi/XBRToken.json')
  124. XBR_NETWORK_FN = pkg_resources.resource_filename('xbr', 'abi/XBRNetwork.json')
  125. XBR_DOMAIN_FN = pkg_resources.resource_filename('xbr', 'abi/XBRDomain.json')
  126. XBR_CATALOG_FN = pkg_resources.resource_filename('xbr', 'abi/XBRCatalog.json')
  127. XBR_MARKET_FN = pkg_resources.resource_filename('xbr', 'abi/XBRMarket.json')
  128. XBR_CHANNEL_FN = pkg_resources.resource_filename('xbr', 'abi/XBRChannel.json')
  129. #
  130. # XBR contract ABIs
  131. #
  132. XBR_TOKEN_ABI = _load_json('XBRToken')['abi']
  133. XBR_NETWORK_ABI = _load_json('XBRNetwork')['abi']
  134. XBR_DOMAIN_ABI = _load_json('XBRDomain')['abi']
  135. XBR_CATALOG_ABI = _load_json('XBRCatalog')['abi']
  136. XBR_MARKET_ABI = _load_json('XBRMarket')['abi']
  137. XBR_CHANNEL_ABI = _load_json('XBRChannel')['abi']