Hashkings NFT Smart Contract

{"id":"ssc-mainnet-hive","json":{"contractName":"contract","contractAction":"deploy","contractPayload":{"name":"HashkingsNFT","params":"","code":"LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBlc2xpbnQtZGlzYWJsZSBtYXgtbGVuICovCi8qIGdsb2JhbCBhY3Rpb25zLCBhcGkgKi8KCmNvbnN0IENPTlRSQUNUX05BTUUgPSAnSGFzaGtpbmdzTkZUJzsKY29uc3QgQ09OVFJBQ1RfQ1JFQVRPUiA9ICdoYXNoa2luZ3MnOwpjb25zdCBVVElMSVRZX1RPS0VOX1NZTUJPTCA9ICJNT1RBIjsKCmNvbnN0IFNFRURTX1BFUl9QQUNLID0gMzsKCmFjdGlvbnMuY3JlYXRlU1NDID0gYXN5bmMgKCkgPT4gewogICAgY29uc3QgdGFibGVFeGlzdHMgPSBhd2FpdCBhcGkuZGIudGFibGVFeGlzdHMoJ3BhcmFtcycpOwogICAgaWYgKHRhYmxlRXhpc3RzID09PSBmYWxzZSkgewogICAgICAgIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgncGFyYW1zJyk7CiAgICAgICAgbGV0IHBhcmFtcyA9IHt9OwoKICAgICAgICBwYXJhbXMuU0VFRFMgPSBbCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIDA6IHsKICAgICAgICAgICAgICAgICAgICBTUFQ6IDEsLy9TcHJvdXRpbmcgdGltZQogICAgICAgICAgICAgICAgICAgIFdBVEVSOiAyMzUsCiAgICAgICAgICAgICAgICAgICAgUFI6IHsgbWluOiA3NTUwLCBtYXg6IDgwMDAgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiQWNlaCIsCiAgICAgICAgICAgICAgICAgICAgY2hhbmNlOiA5MCwKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAxOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiAyLC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogMjM1LAogICAgICAgICAgICAgICAgICAgIFBSOiB7IG1pbjogNzI1MCwgbWF4OiA3ODAwIH0sLy9Qcm9kdWN0aW9uIHJhbmdlICAgCiAgICAgICAgICAgICAgICAgICAgTkFNRTogIlRoYWkiLAogICAgICAgICAgICAgICAgICAgIGNoYWNlOiA2MAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIDI6IHsKICAgICAgICAgICAgICAgICAgICBTUFQ6IDIsLy9TcHJvdXRpbmcgdGltZQogICAgICAgICAgICAgICAgICAgIFdBVEVSOiAyMzAsCiAgICAgICAgICAgICAgICAgICAgUFI6IHsgbWluOiA3MDAwLCBtYXg6IDczMDAgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiVGhhaSBDaG9jb2xhdGUiLAogICAgICAgICAgICAgICAgICAgIGNoYW5jZTogNTAKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIDA6IHsKICAgICAgICAgICAgICAgICAgICBTUFQ6IDIsLy9TcHJvdXRpbmcgdGltZQogICAgICAgICAgICAgICAgICAgIFdBVEVSOiAyMTUsCiAgICAgICAgICAgICAgICAgICAgUFI6IHsgbWluOiA2MDAwLCBtYXg6IDcwMDAgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiTGFtYuKAmXMgQnJlYWQiLAogICAgICAgICAgICAgICAgICAgIGNoYW5jZTogNzAKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAxOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiAzLC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogMjA1LAogICAgICAgICAgICAgICAgICAgIFBSOiB7IG1pbjogNTUwMCwgbWF4OiA2NTAwIH0sLy9Qcm9kdWN0aW9uIHJhbmdlICAgCiAgICAgICAgICAgICAgICAgICAgTkFNRTogIktpbmfigJlzIEJyZWFkIiwKICAgICAgICAgICAgICAgICAgICBjaGFuY2U6IDMwCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAwOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiAzLC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogMTY4LAogICAgICAgICAgICAgICAgICAgIFBSOiB7IG1pbjogNDYwMCwgbWF4OiA0OTAwIH0sLy9Qcm9kdWN0aW9uIHJhbmdlICAgCiAgICAgICAgICAgICAgICAgICAgTkFNRTogIlN3YXppIEdvbGQiLAogICAgICAgICAgICAgICAgICAgIGNoYW5jZTogOTAKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAxOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiAzLC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogMTM3LAogICAgICAgICAgICAgICAgICAgIFBSOiB7IG1pbjogMzUwMCwgbWF4OiAzOTAwIH0sLy9Qcm9kdWN0aW9uIHJhbmdlICAgCiAgICAgICAgICAgICAgICAgICAgTkFNRTogIktpbGltYW5qYXJvIiwKICAgICAgICAgICAgICAgICAgICBjaGFuY2U6IDgwCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgMjogewogICAgICAgICAgICAgICAgICAgIFNQVDogNCwvL1Nwcm91dGluZyB0aW1lCiAgICAgICAgICAgICAgICAgICAgV0FURVI6IDEwNCwKICAgICAgICAgICAgICAgICAgICBQUjogeyBtaW46IDI1NzUsIG1heDogMjkyNSB9LC8vUHJvZHVjdGlvbiByYW5nZSAgIAogICAgICAgICAgICAgICAgICAgIE5BTUU6ICJEdXJiYW4gUG9pc29uIiwKICAgICAgICAgICAgICAgICAgICBjaGFuY2U6IDc1CiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgMzogewogICAgICAgICAgICAgICAgICAgIFNQVDogNCwvL1Nwcm91dGluZyB0aW1lCiAgICAgICAgICAgICAgICAgICAgV0FURVI6IDkzLAogICAgICAgICAgICAgICAgICAgIFBSOiB7IG1pbjogMjE3NSwgbWF4OiAyNTI1IH0sLy9Qcm9kdWN0aW9uIHJhbmdlICAgCiAgICAgICAgICAgICAgICAgICAgTkFNRTogIk1hbGF3aSIsCiAgICAgICAgICAgICAgICAgICAgY2hhbmNlOiA1NQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAwOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiA0LC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogODIsCiAgICAgICAgICAgICAgICAgICAgUFI6IHsgbWluOiAxODI1LCBtYXg6IDIxNzUgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiSGluZHUgS3VzaCIsCiAgICAgICAgICAgICAgICAgICAgY2hhbmNlOiA5NQogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIDE6IHsKICAgICAgICAgICAgICAgICAgICBTUFQ6IDUsLy9TcHJvdXRpbmcgdGltZQogICAgICAgICAgICAgICAgICAgIFdBVEVSOiA3MCwKICAgICAgICAgICAgICAgICAgICBQUjogeyBtaW46IDE0NTAsIG1heDogMTgwMCB9LC8vUHJvZHVjdGlvbiByYW5nZSAgIAogICAgICAgICAgICAgICAgICAgIE5BTUU6ICJBZmdoYW5pIiwKICAgICAgICAgICAgICAgICAgICBjaGFuY2U6IDgwCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgMjogewogICAgICAgICAgICAgICAgICAgIFNQVDogNSwvL1Nwcm91dGluZyB0aW1lCiAgICAgICAgICAgICAgICAgICAgV0FURVI6IDQzLAogICAgICAgICAgICAgICAgICAgIFBSOiB7IG1pbjogODUwLCBtYXg6IDExMDAgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiTGFzaGthciBHYWgiLAogICAgICAgICAgICAgICAgICAgIGNoYW5jZTogNzUKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAzOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiA2LC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogMzMsCiAgICAgICAgICAgICAgICAgICAgUFI6IHsgbWluOiA2MDAsIG1heDogODUwIH0sLy9Qcm9kdWN0aW9uIHJhbmdlICAgCiAgICAgICAgICAgICAgICAgICAgTkFNRTogIk1hemFyIEkgU2hhcmlmIiwKICAgICAgICAgICAgICAgICAgICBjaGFuY2U6IDUwCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIDA6IHsKICAgICAgICAgICAgICAgICAgICBTUFQ6IDYsLy9TcHJvdXRpbmcgdGltZQogICAgICAgICAgICAgICAgICAgIFdBVEVSOiAyMywKICAgICAgICAgICAgICAgICAgICBQUjogeyBtaW46IDM1MCwgbWF4OiA2MDAgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiQWNhcHVsY28gR29sZCIsCiAgICAgICAgICAgICAgICAgICAgY2hhbmNlOiAwCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAwOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiA3LC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogMTAsCiAgICAgICAgICAgICAgICAgICAgUFI6IHsgbWluOiA1MCwgbWF4OiAzNTAgfSwvL1Byb2R1Y3Rpb24gcmFuZ2UgICAKICAgICAgICAgICAgICAgICAgICBOQU1FOiAiQ29sb21iaWFuIEdvbGQiLAogICAgICAgICAgICAgICAgICAgIGNoYW5jZTogNjAKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAxOiB7CiAgICAgICAgICAgICAgICAgICAgU1BUOiA3LC8vU3Byb3V0aW5nIHRpbWUKICAgICAgICAgICAgICAgICAgICBXQVRFUjogOSwKICAgICAgICAgICAgICAgICAgICBQUjogeyBtaW46IDMwLCBtYXg6IDMyNSB9LC8vUHJvZHVjdGlvbiByYW5nZSAgIAogICAgICAgICAgICAgICAgICAgIE5BTUU6ICJQYW5hbWEgcmVkIiwKICAgICAgICAgICAgICAgICAgICBjaGFuY2U6IDQwCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICBdOwogICAgICAgIGF3YWl0IGFwaS5kYi5pbnNlcnQoJ3BhcmFtcycsIHBhcmFtcyk7CiAgICB9Cn07Cgpjb25zdCBpc1Rva2VuVHJhbnNmZXJWZXJpZmllZCA9IChyZXN1bHQsIGZyb20sIHRvLCBzeW1ib2wsIHF1YW50aXR5LCBldmVudFN0cikgPT4gewogICAgaWYgKHJlc3VsdC5lcnJvcnMgPT09IHVuZGVmaW5lZAogICAgICAgICYmIHJlc3VsdC5ldmVudHMgJiYgcmVzdWx0LmV2ZW50cy5maW5kKGVsID0+IGVsLmNvbnRyYWN0ID09PSAndG9rZW5zJyAmJiBlbC5ldmVudCA9PT0gZXZlbnRTdHIKICAgICAgICAgICAgJiYgZWwuZGF0YS5mcm9tID09PSBmcm9tICYmIGVsLmRhdGEudG8gPT09IHRvICYmIGVsLmRhdGEucXVhbnRpdHkgPT09IHF1YW50aXR5ICYmIGVsLmRhdGEuc3ltYm9sID09PSBzeW1ib2wpICE9PSB1bmRlZmluZWQpIHsKICAgICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIHJldHVybiBmYWxzZTsKfTsKCmFjdGlvbn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250cmFjdCgnbmZ0JywgJ2NyZWF0ZScsIHsKICAgICAgICAgICAgbmFtZTogJ0hhc2hraW5nc05GVCcsCiAgICAgICAgICAgIHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgICAgIGF1dGhvcml6ZWRJc3N1aW5nQWNjb3VudHM6IFtdLAogICAgICAgICAgICBhdXRob3JpemVkSXNzdWluZ0NvbnRyYWN0czogW0NPTlRSQUNUX05BTUVdLAogICAgICAgICAgICBpc1NpZ25lZFdpdGhBY3RpdmVLZXksCiAgICAgICAgICAgIG9yZ05hbWU6ICJIYXNoa2luZ3MgVGVhbSIsCiAgICAgICAgICAgIHByb2R1Y3ROYW1lOiAiSGFzaGtpbmdzIEdhbWUiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL3d3dy5oYXNoa2luZ3MuYXBwLyIsCiAgICAgICAgfSk7CgogICAgICAgIC8vQUxMCiAgICAgICAgYXdhaXQgYXBpLmV4ZWN1dGVTbWFydENvbnRyYWN0KCduZnQnLCAnYWRkUHJvcGVydHknLCB7CiAgICAgICAgICAgIHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgICAgIG5hbWU6ICdOQU1FJywKICAgICAgICAgICAgdHlwZTogJ3N0cmluZycsCiAgICAgICAgICAgIGlzUmVhZE9ubHk6IGZhbHNlLAogICAgICAgICAgICBhdXRob3JpemVkRWRpdGluZ0FjY291bnRzOiBbXSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdDb250cmFjdHM6IFtDT05UUkFDVF9OQU1FXSwKICAgICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwoKICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICdhZGRQcm9wZXJ0eScsIHsKICAgICAgICAgICAgc3ltYm9sOiBVVElMSVRZX1RPS0VOX1NZTUJPTCwKICAgICAgICAgICAgbmFtZTogJ1RZUEUnLAogICAgICAgICAgICB0eXBlOiAnc3RyaW5nJywKICAgICAgICAgICAgaXNSZWFkT25seTogdHJ1ZSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdBY2NvdW50czogW10sCiAgICAgICAgICAgIGF1dGhvcml6ZWRFZGl0aW5nQ29udHJhY3RzOiBbQ09OVFJBQ1RfTkFNRV0sCiAgICAgICAgICAgIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICB9KTsKICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICdhZGRQcm9wZXJ0eScsIHsKICAgICAgICAgICAgc3ltYm9sOiBVVElMSVRZX1RPS0VOX1NZTUJPTCwKICAgICAgICAgICAgbmFtZTogJ1NUUkFJTicsCiAgICAgICAgICAgIHR5cGU6ICdudW1iZXInLAogICAgICAgICAgICBpc1JlYWRPbmx5OiB0cnVlLAogICAgICAgICAgICBhdXRob3JpemVkRWRpdGluZ0FjY291bnRzOiBbXSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdDb250cmFjdHM6IFtDT05UUkFDVF9OQU1FXSwKICAgICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwogICAgICAgIGF3YWl0IGFwaS5leGVjdXRlU21hcnRDb250cmFjdCgnbmZ0JywgJ2FkZFByb3BlcnR5JywgewogICAgICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgICAgICBuYW1lOiAnU1BUJywKICAgICAgICAgICAgdHlwZTogJ251bWJlcicsCiAgICAgICAgICAgIGlzUmVhZE9ubHk6IHRydWUsCiAgICAgICAgICAgIGF1dGhvcml6ZWRFZGl0aW5nQWNjb3VudHM6IFtdLAogICAgICAgICAgICBhdXRob3JpemVkRWRpdGluZ0NvbnRyYWN0czogW0NPTlRSQUNUX05BTUVdLAogICAgICAgICAgICBpc1NpZ25lZFdpdGhBY3RpdmVLZXksCiAgICAgICAgfSk7CiAgICAgICAgYXdhaXQgYXBpLmV4ZWN1dGVTbWFydENvbnRyYWN0KCduZnQnLCAnYWRkUHJvcGVydHknLCB7CiAgICAgICAgICAgIHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgICAgIG5hbWU6ICdXQVRFUicsCiAgICAgICAgICAgIHR5cGU6ICdudW1iZXInLAogICAgICAgICAgICBpc1JlYWRPbmx5OiB0cnVlLAogICAgICAgICAgICBhdXRob3JpemVkRWRpdGluZ0FjY291bnRzOiBbXSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdDb250cmFjdHM6IFtDT05UUkFDVF9OQU1FXSwKICAgICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwogICAgICAgIGF3YWl0IGFwaS5leGVjdXRlU21hcnRDb250cmFjdCgnbmZ0JywgJ2FkZFByb3BlcnR5JywgewogICAgICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgICAgICBuYW1lOiAnUFInLCAvLyBhdHRhY2sgcG9pbnRzCiAgICAgICAgICAgIHR5cGU6ICdudW1iZXInLAogICAgICAgICAgICBpc1JlYWRPbmx5OiB0cnVlLAogICAgICAgICAgICBhdXRob3JpemVkRWRpdGluZ0FjY291bnRzOiBbXSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdDb250cmFjdHM6IFtDT05UUkFDVF9OQU1FXSwKICAgICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwogICAgICAgIGF3YWl0IGFwaS5leGVjdXRlU21hcnRDb250cmFjdCgnbmZ0JywgJ2FkZFByb3BlcnR5JywgewogICAgICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgICAgICBuYW1lOiAnTFZMJywgLy8gZXhwZXJpZW5jaWUgcG9pbnRzCiAgICAgICAgICAgIHR5cGU6ICdudW1iZXInLAogICAgICAgICAgICBpc1JlYWRPbmx5OiBmYWxzZSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdBY2NvdW50czogW10sCiAgICAgICAgICAgIGF1dGhvcml6ZWRFZGl0aW5nQ29udHJhY3RzOiBbQ09OVFJBQ1RfTkFNRV0sCiAgICAgICAgICAgIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICB9KTsKICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICdhZGRQcm9wZXJ0eScsIHsKICAgICAgICAgICAgc3ltYm9sOiBVVElMSVRZX1RPS0VOX1NZTUJPTCwKICAgICAgICAgICAgbmFtZTogJ0NPTlNVTUFCTEVUWVBFJywgLy8gZXhwZXJpZW5jaWUgcG9pbnRzCiAgICAgICAgICAgIHR5cGU6ICdzdHJpbmcnLAogICAgICAgICAgICBpc1JlYWRPbmx5OiB0cnVlLAogICAgICAgICAgICBhdXRob3JpemVkRWRpdGluZ0FjY291bnRzOiBbXSwKICAgICAgICAgICAgYXV0aG9yaXplZEVkaXRpbmdDb250cmFjdHM6IFtDT05UUkFDVF9OQU1FXSwKICAgICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwogICAgfQp9OwoKCmNvbnN0IGdldFBsb3QgPSAoKSA9PiB7CgogICAgbGV0IHR5cGUgPSA2OwogICAgbGV0IHR5cGVSb2xsID0gTWF0aC5mbG9vcihhcGkucmFuZG9tKCkgKiAxMDApICsgMTsKCiAgICBpZiAodHlwZVJvbGwgPiA5NykgeyAvLzMKICAgICAgICB0eXBlID0gMTsKICAgIH0gZWxzZSBpZiAodHlwZVJvbGwgPiA5NCkgeyAvLzYKICAgICAgICB0eXBlID0gMgogICAgfSBlbHNlIGlmICh0eXBlUm9sbCA+IDg5KSB7IC8vMTEKICAgICAgICB0eXBlID0gMzsKICAgIH0gZWxzZSBpZiAodHlwZVJvbGwgPiA4NSkgeyAvLzE1CiAgICAgICAgdHlwZSA9IDQ7CiAgICB9IGVsc2UgaWYgKHR5cGVSb2xsID4gNzUpIHsgLy8yNQogICAgICAgIHR5cGUgPSA1OwogICAgfSBlbHNlIGlmICh0eXBlUm9sbCA+IDYwKSB7IC8vMjUKICAgICAgICB0eXBlID0gNjsKICAgIH0KCiAgICByZXR1cm4gdHlwZTsKfQoKY29uc3QgZ2VuZXJhdGVSYW5kb21TZWVkID0gKHRvLCBTRUVEUykgPT4gewoKICAgIGNvbnN0IHR5cGUgPSBnZXRQbG90KCk7CiAgICBsZXQgcHJvcGVydGllcyA9IHt9OwogICAgaWYgKHR5cGUgPT0gMSkgewogICAgICAgIGxldCBwbG90ID0gU0VFRFNbMF07CiAgICAgICAgbGV0IHNlZWQgPSBwbG90W09iamVjdC5rZXlzKHBsb3QpLmxlbmd0aCAtIDFdOwogICAgICAgIGxldCB0eXBlUm9sbCA9IE1hdGguZmxvb3IoYXBpLnJhbmRvbSgpICogMTAwKSArIDE7CgogICAgICAgIGxldCBmb3VuZCA9IGZhbHNlOwogICAgICAgIGZvciAobGV0IGluZGV4ID0gMDsgaW5kZXggPCBPYmplY3Qua2V5cyhwbG90KS5sZW5ndGg7IGluZGV4KyspIHsKICAgICAgICAgICAgY29uc3QgZWxlbWVudCA9IHBsb3RbaW5kZXhdOwogICAgICAgICAgICBpZiAoIWZvdW5kICYmIHR5cGVSb2xsID4gZWxlbWVudC5jaGFuY2UpIHsKICAgICAgICAgICAgICAgIHNlZWQgPSBlbGVtZW50OwogICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBwcm9wZXJ0aWVzLk5BTUUgPSBzZWVkLk5BTUU7CiAgICAgICAgcHJvcGVydGllcy5TUFQgPSBzZWVkLlNQVDsKICAgICAgICBwcm9wZXJ0aWVzLldBVEVSID0gc2VlZC5XQVRFUjsKICAgICAgICBwcm9wZXJ0aWVzLlBSID0gTWF0aC5mbG9vcihhcGkucmFuZG9tKCkgKiBzZWVkLlBSLm1heCkgKyBzZWVkLlBSLm1pbjsKCiAgICB9IGVsc2UgaWYgKHR5cGUgPT0gMikgewogICAgICAgIGxldCBwbG90ID0gU0VFRFNbMV07CiAgICAgICAgbGV0IHNlZWQgPSBwbG90W09iamVjdC5rZXlzKHBsb3QpLmxlbmd0aCAtIDFdOwogICAgICAgIGxldCB0eXBlUm9sbCA9IE1hdGguZmxvb3IoYXBpLnJhbmRvbSgpICogMTAwKSArIDE7CgoKICAgICAgICBsZXQgZm91bmQgPSBmYWxzZTsKICAgICAgICBmb3IgKGxldCBpbmRleCA9IDA7IGluZGV4IDwgT2JqZWN0LmtleXMocGxvdCkubGVuZ3RoOyBpbmRleCsrKSB7CiAgICAgICAgICAgIGNvbnN0IGVsZW1lbnQgPSBwbG90W2luZGV4XTsKICAgICAgICAgICAgaWYgKCFmb3VuZCAmJiB0eXBlUm9sbCA+IGVsZW1lbnQuY2hhbmNlKSB7CiAgICAgICAgICAgICAgICBzZWVkID0gZWxlbWVudDsKICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgIH0KCgogICAgICAgIHByb3BlcnRpZXMuTkFNRSA9IHNlZWQuTkFNRTsKICAgICAgICBwcm9wZXJ0aWVzLlNQVCA9IHNlZWQuU1BUOwogICAgICAgIHByb3BlcnRpZXMuV0FURVIgPSBzZWVkLldBVEVSOwogICAgICAgIHByb3BlcnRpZXMuUFIgPSBNYXRoLmZsb29yKGFwaS5yYW5kb20oKSAqIHNlZWQuUFIubWF4KSArIHNlZWQuUFIubWluOwogICAgfSBlbHNlIGlmICh0eXBlID09IDMpIHsKICAgICAgICBsZXQgcGxvdCA9IFNFRURTWzJdOwogICAgICAgIGxldCBzZWVkID0gcGxvdFtPYmplY3Qua2V5cyhwbG90KS5sZW5ndGggLSAxXTsKICAgICAgICBsZXQgdHlwZVJvbGwgPSBNYXRoLmZsb29yKGFwaS5yYW5kb20oKSAqIDEwMCkgKyAxOwoKCiAgICAgICAgbGV0IGZvdW5kID0gZmFsc2U7CiAgICAgICAgZm9yIChsZXQgaW5kZXggPSAwOyBpbmRleCA8IE9iamVjdC5rZXlzKHBsb3QpLmxlbmd0aDsgaW5kZXgrKykgewogICAgICAgICAgICBjb25zdCBlbGVtZW50ID0gcGxvdFtpbmRleF07CiAgICAgICAgICAgIGlmICghZm91bmQgJiYgdHlwZVJvbGwgPiBlbGVtZW50LmNoYW5jZSkgewogICAgICAgICAgICAgICAgc2VlZCA9IGVsZW1lbnQ7CiAgICAgICAgICAgICAgICBmb3VuZCA9IHRydWU7CiAgICAgICAgICAgIH0KICAgICAgICB9CgoKICAgICAgICBwcm9wZXJ0aWVzLk5BTUUgPSBzZWVkLk5BTUU7CiAgICAgICAgcHJvcGVydGllcy5TUFQgPSBzZWVkLlNQVDsKICAgICAgICBwcm9wZXJ0aWVzLldBVEVSID0gc2VlZC5XQVRFUjsKICAgICAgICBwcm9wZXJ0aWVzLlBSID0gTWF0aC5mbG9vcihhcGkucmFuZG9tKCkgKiBzZWVkLlBSLm1heCkgKyBzZWVkLlBSLm1pbjsKICAgIH0gZWxzZSBpZiAodHlwZSA9PSA0KSB7CiAgICAgICAgbGV0IHBsb3QgPSBTRUVEU1szXTsKICAgICAgICBsZXQgc2VlZCA9IHBsb3RbT2JqZWN0LmtleXMocGxvdCkubGVuZ3RoIC0gMV07CiAgICAgICAgbGV0IHR5cGVSb2xsID0gTWF0aC5mbG9vcihhcGkucmFuZG9tKCkgKiAxMDApICsgMTsKCgogICAgICAgIGxldCBmb3VuZCA9IGZhbHNlOwogICAgICAgIGZvciAobGV0IGluZGV4ID0gMDsgaW5kZXggPCBPYmplY3Qua2V5cyhwbG90KS5sZW5ndGg7IGluZGV4KyspIHsKICAgICAgICAgICAgY29uc3QgZWxlbWVudCA9IHBsb3RbaW5kZXhdOwogICAgICAgICAgICBpZiAoIWZvdW5kICYmIHR5cGVSb2xsID4gZWxlbWVudC5jaGFuY2UpIHsKICAgICAgICAgICAgICAgIHNlZWQgPSBlbGVtZW50OwogICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfQoKCiAgICAgICAgcHJvcGVydGllcy5OQU1FID0gc2VlZC5OQU1FOwogICAgICAgIHByb3BlcnRpZXMuU1BUID0gc2VlZC5TUFQ7CiAgICAgICAgcHJvcGVydGllcy5XQVRFUiA9IHNlZWQuV0FURVI7CiAgICAgICAgcHJvcGVydGllcy5QUiA9IE1hdGguZmxvb3IoYXBpLnJhbmRvbSgpICogc2VlZC5QUi5tYXgpICsgc2VlZC5QUi5taW47CiAgICB9IGVsc2UgaWYgKHR5cGUgPT0gNSkgewogICAgICAgIGxldCBwbG90ID0gU0VFRFNbNF07CiAgICAgICAgbGV0IHNlZWQgPSBwbG90W09iamVjdC5rZXlzKHBsb3QpLmxlbmd0aCAtIDFdOwogICAgICAgIGxldCB0eXBlUm9sbCA9IE1hdGguZmxvb3IoYXBpLnJhbmRvbSgpICogMTAwKSArIDE7CgoKICAgICAgICBsZXQgZm91bmQgPSBmYWxzZTsKICAgICAgICBmb3IgKGxldCBpbmRleCA9IDA7IGluZGV4IDwgT2JqZWN0LmtleXMocGxvdCkubGVuZ3RoOyBpbmRleCsrKSB7CiAgICAgICAgICAgIGNvbnN0IGVsZW1lbnQgPSBwbG90W2luZGV4XTsKICAgICAgICAgICAgaWYgKCFmb3VuZCAmJiB0eXBlUm9sbCA+IGVsZW1lbnQuY2hhbmNlKSB7CiAgICAgICAgICAgICAgICBzZWVkID0gZWxlbWVudDsKICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgIH0KCgogICAgICAgIHByb3BlcnRpZXMuTkFNRSA9IHNlZWQuTkFNRTsKICAgICAgICBwcm9wZXJ0aWVzLlNQVCA9IHNlZWQuU1BUOwogICAgICAgIHByb3BlcnRpZXMuV0FURVIgPSBzZWVkLldBVEVSOwogICAgICAgIHByb3BlcnRpZXMuUFIgPSBNYXRoLmZsb29yKGFwaS5yYW5kb20oKSAqIHNlZWQuUFIubWF4KSArIHNlZWQuUFIubWluOwoKICAgIH0gZWxzZSBpZiAodHlwZSA9PSA2KSB7CiAgICAgICAgbGV0IHBsb3QgPSBTRUVEU1s1XTsKICAgICAgICBsZXQgc2VlZCA9IHBsb3RbT2JqZWN0LmtleXMocGxvdCkubGVuZ3RoIC0gMV07CiAgICAgICAgbGV0IHR5cGVSb2xsID0gTWF0aC5mbG9vcihhcGkucmFuZG9tKCkgKiAxMDApICsgMTsKCgogICAgICAgIGxldCBmb3VuZCA9IGZhbHNlOwogICAgICAgIGZvciAobGV0IGluZGV4ID0gMDsgaW5kZXggPCBPYmplY3Qua2V5cyhwbG90KS5sZW5ndGg7IGluZGV4KyspIHsKICAgICAgICAgICAgY29uc3QgZWxlbWVudCA9IHBsb3RbaW5kZXhdOwogICAgICAgICAgICBpZiAoIWZvdW5kICYmIHR5cGVSb2xsID4gZWxlbWVudC5jaGFuY2UpIHsKICAgICAgICAgICAgICAgIHNlZWQgPSBlbGVtZW50OwogICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfQoKCiAgICAgICAgcHJvcGVydGllcy5OQU1FID0gc2VlZC5OQU1FOwogICAgICAgIHByb3BlcnRpZXMuU1BUID0gc2VlZC5TUFQ7CiAgICAgICAgcHJvcGVydGllcy5XQVRFUiA9IHNlZWQuV0FURVI7CiAgICAgICAgcHJvcGVydGllcy5QUiA9IE1hdGguZmxvb3IoYXBpLnJhbmRvbSgpICogc2VlZC5QUi5tYXgpICsgc2VlZC5QUi5taW47CiAgICB9CgogICAgY29uc3QgcHJvcGVydHlzID0gewogICAgICAgIFRZUEU6ICJzZWVkIiwKICAgICAgICBOQU1FOiBwcm9wZXJ0aWVzLk5BTUUsCiAgICAgICAgU1BUOiBwcm9wZXJ0aWVzLlNQVCwKICAgICAgICBXQVRFUjogcHJvcGVydGllcy5XQVRFUiwKICAgICAgICBQUjogcHJvcGVydGllcy5QUgogICAgfTsKCiAgICBjb25zdCBpbnN0YW5jZSA9IHsKICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgIGZyb21UeXBlOiAnY29udHJhY3QnLAogICAgICAgIHRvLAogICAgICAgIGZlZVN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgcHJvcGVydHlzLAogICAgfTsKCiAgICByZXR1cm4gaW5zdGFuY2U7Cn07Cgpjb25zdCBDcmVhdGVCdWQgPSAobmFtZUJ1ZE5GVCwgdG8pID0+IHsKCiAgICBjb25zdCBwcm9wZXJ0aWVzID0gewogICAgICAgIE5BTUU6IG5hbWVCdWRORlQsCiAgICAgICAgVFlQRTogImJ1ZCIsCiAgICB9OwoKICAgIGNvbnN0IGluc3RhbmNlID0gewogICAgICAgIHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgZnJvbVR5cGU6ICdjb250cmFjdCcsCiAgICAgICAgdG8sCiAgICAgICAgZmVlU3ltYm9sOiBVVElMSVRZX1RPS0VOX1NZTUJPTCwKICAgICAgICBwcm9wZXJ0aWVzLAogICAgfTsKCiAgICByZXR1cm4gaW5zdGFuY2U7Cn0KCmNvbnN0IENyZWF0ZVdhdGVyID0gKG5hbWVXYXRlck5GVCwgdG8pID0+IHsKCiAgICBjb25zdCBwcm9wZXJ0aWVzID0gewogICAgICAgIE5BTUU6IG5hbWVXYXRlck5GVCwKICAgICAgICBUWVBFOiAid2F0ZXIiLAogICAgfTsKCiAgICBjb25zdCBpbnN0YW5jZSA9IHsKICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgIGZyb21UeXBlOiAnY29udHJhY3QnLAogICAgICAgIHRvLAogICAgICAgIGZlZVN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgcHJvcGVydGllcywKICAgIH07CgogICAgcmV0dXJuIGluc3RhbmNlOwp9Cgpjb25zdCBDcmVhdGVQbG90ID0gKGxvY2F0aW9uLCB0bykgPT4gewoKICAgIGNvbnN0IHByb3BlcnRpZXMgPSB7CiAgICAgICAgTkFNRTogbG9jYXRpb24sCiAgICAgICAgVFlQRTogInBsb3QiLAogICAgfTsKCiAgICBjb25zdCBpbnN0YW5jZSA9IHsKICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgIGZyb21UeXBlOiAnY29udHJhY3QnLAogICAgICAgIHRvLAogICAgICAgIGZlZVN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgcHJvcGVydGllcywKICAgIH07CgogICAgcmV0dXJuIGluc3RhbmNlOwp9Cgpjb25zdCBDcmVhdGVCb29zdGVyID0gKG5hbWUsIGNvbnN1bWFibGVUeXBlLCB0bykgPT4gewoKICAgIGNvbnN0IHByb3BlcnRpZXMgPSB7CiAgICAgICAgTkFNRTogbmFtZSwKICAgICAgICBUWVBFOiAiYm9vc3RlciIsCiAgICAgICAgQ09OU1VNQUJMRVRZUEU6IGNvbnN1bWFibGVUeXBlLAogICAgICAgIExWTDogMAogICAgfTsKCiAgICBjb25zdCBpbnN0YW5jZSA9IHsKICAgICAgICBzeW1ib2w6IFVUSUxJVFlfVE9LRU5fU1lNQk9MLAogICAgICAgIGZyb21UeXBlOiAnY29udHJhY3QnLAogICAgICAgIHRvLAogICAgICAgIGZlZVN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsCiAgICAgICAgcHJvcGVydGllcywKICAgIH07CgogICAgcmV0dXJuIGluc3RhbmNlOwp9CgphY3Rpb25zLmNyZWF0ZUJ1ZCA9IGFzeW5jIChwYXlsb2FkKSA9PiB7CiAgICBpZiAoYXBpLnNlbmRlciAhPT0gQ09OVFJBQ1RfQ1JFQVRPUikgcmV0dX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pLmV4ZWN1dGVTbWFydENvbnRyYWN0KCduZnQnLCAnaXNzdWVNdWx0aXBsZScsIHsKICAgICAgICAgICAgICAgIGluc3RhbmNlcywKICAgICAgICAgICAgICAgIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBmYWxzZTsKfTs="}}}

H2
H3
H4
3 columns
2 columns
1 column
Join the conversion now