You are viewing a single comment's thread from:RE: Hive Engine SMT (Comments) Contract LaunchView the full contextView the direct parenteonwarped (69)in Palnet • 3 years ago (edited)removed
removed
{ "id": "ssc-testnet-hive", "json": { "contractName":"contract", "contractAction":"update", "contractPayload":{ "name":"comments", "params":"", "code":"LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBlc2xpbnQgbm8tdW5kZXJzY29yZS1kYW5nbGU6IFsiZXJyb3IiLCB7ICJhbGxvdyI6IFsiX2lkIl0gfV0gKi8KLyogZ2xvYmFsIGFjdGlvbnMsIGFwaSAqLwoKY29uc3QgU01UX1BSRUNJU0lPTiA9IDEwOwpjb25zdCBNQVhfVk9USU5HX1BPV0VSID0gMTAwMDA7CmNvbnN0IE1BWF9XRUlHSFQgPSAxMDAwMDsKCmFjdGlvbnMuY3JlYXRlU1NDID0gYXN5bmMgKCkgPT4gewogIGNvbnN0IHRhYmxlRXhpc3RzID0gYXdhaXQgYXBpLmRiLnRhYmxlRXhpc3RzKCdyZXdhcmRQb29scycpOwogIGlmICh0YWJsZUV4aXN0cyA9PT0gZmFsc2UpIHsKICAgIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgncGFyYW1zJyk7CiAgICBhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoJ3Jld2FyZFBvb2xzJywgWydjb25maWcudGFncycsICdsYXN0Q2xhaW1EZWNheVRpbWVzdGFtcCddKTsKICAgIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgncG9zdHMnLCBbCiAgICAgICdhdXRob3JwZXJtJywKICAgICAgeyBuYW1lOiAnYnlDYXNob3V0VGltZScsIGluZGV4OiB7IHJld2FyZFBvb2xJZDogMSwgY2FzaG91dFRpbWU6IDEgfSB9LAogICAgXSwgeyBwcmltYXJ5S2V5OiBbJ2F1dGhvcnBlcm0nLCAncmV3YXJkUG9vbElkJ10gfSk7CiAgICBhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoJ3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xzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgIGNvbnN0IHJld2FyZFBvb2wgPSByZXdhcmRQb29sc1tpXTsKICAgICAgcGFyYW1zLmxhc3RQcm9jZXNzZWRQb29sSWQgPSByZXdhcmRQb29sLl9pZDsKICAgICAgY29uc3QgewogICAgICAgIGxhc3RDbGFpbURlY2F5VGltZXN0YW1wLAogICAgICAgIGxhc3RSZXdhcmRUaW1lc3RhbXAsCiAgICAgICAgY29uZmlnLAogICAgICB9ID0gcmV3YXJkUG9vbDsKICAgICAgY29uc3QgewogICAgICAgIHN5bWJvbCwKICAgICAgICByZXdhcmRJbnRlcnZhbFNlY29uZHMsCiAgICAgICAgcmV3YXJkUGVySW50ZXJ2YWwsCiAgICAgICAgY2FzaG91dFdpbmRvd0RheXMsCiAgICAgIH0gPSBjb25maWc7CiAgICAgIGNvbnN0IHRva2VuID0gYXdhaXQgYXBpLmRiLmZpbmRPbmVJblRhYmxlKCd0b2tlbnMnLCAndG9rZW5zJywgeyBzeW1ib2wgfSk7CiAgICAgIGNvbnN0IHJld2FyZEludGVydmFsRHVyYXRpb25NaWxsaXMgPSByZXdhcmRJbnRlcnZhbFNlY29uZHMgKiAxMDAwOwogICAgICBjb25zdCBuZXh0UmV3YXJkVGltZXN0YW1wID0gbGFzdFJld2FyZFRpbWVzdGFtcCArIHJld2FyZEludGVydmFsRHVyYXRpb25NaWxsaXM7CiAgICAgIGNvbnN0IG5leHRDbGFpbURlY2F5VGltZXN0YW1wID0gbGFzdENsYWltRGVjYXlUaW1lc3RhbXAgKyByZXdhcmRJbnRlcnZhbER1cmF0aW9uTWlsbGlzOwogICAgICBpZiAobmV4dENsYWltRGVjYXlUaW1lc3RhbXAgPj0gbmV4dFJld2FyZFRpbWVzdGFtcCkgewogICAgICAgIGNvbnN0IHJld2FyZFRvQWRkID0gYXBpLkJpZ051bWJlcihyZXdhcmRQZXJJbnRlcnZhbCk7CiAgICAgICAgaWYgKGFwaS5CaWdOdW1iZXIocmV3Y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mJiByZXdhcmRQb29sLmFjdGl2ZSkgewogICAgICBjb25zdCBjYXNob3V0VGltZSA9IHRpbWVzdGFtcCArIHJld2FyZFBvb2wuY29uZmlnLmNhc2hvdXRXaW5kb3dEYXlzICogMjQgKiAzNjAwICogMTAwMDsKCiAgICAgIGNvbnN0IHBvc3QgPSB7CiAgICAgICAgcmV3YXJkUG9vbElkLAogICAgICAgIHN5bWJvbDogcmV3YXJkUG9vbC5zeW1ib2wsCiAgICAgICAgYXV0aG9ycGVybSwKICAgICAgICBhdXRob3IsCiAgICAgICAgY3JlYXRlZDogdGltZXN0YW1wLAogICAgICAgIGNhc2hvdXRUaW1lLAogICAgICAgIHZvdGVQb3NpdGl2ZVJzaGFyZVN1bTogJzAnLAogICAgICAgIHZvdGVSc2hhcmVTdW06ICcwJywKICAgICAgfTsKICAgICAgYXdhaXQgYXBpLmRiLmluc2VydCgncG9zdHMnLCBwb3N0KTsKICAgICAgYXBpLmVtaXQoJ25ld0NvbW1lbnQnLCB7IHJld2FyZFBvb2xJZCwgc3ltYm9sOiByZXdhcmRQb29sLnN5bWJvbCB9KTsKICAgIH0KICB9Cn07CgphY3Rpb25zLmNvbW1lbnRPcHRpb25zID0gYXN5bmMgKHBheWxvYWQpID0+IHsKICBjb25zdCB7CiAgICBhdXRob3IsCiAgICBwZXJtbGluaywKICAgIG1heEFjY2VwdGVkUGF5b3V0LAogICAgYmVuZWZpY2lhcmllcywKICB9ID0gcGF5bG9hZDsKCiAgLy8gTm9kZSBlbmZvcmNlcyBhdXRob3IgLyBwZXJtbGlua3MgZnJvbSBIaXZlLiBDaGVjayB0aGF0IHNlbmRlciBpcyBudWxsLgogIGlmICghYXBpLmFzc2VydChhcGkuc2VuZGVyID09PSAnbnVsbCcsICdhY3Rpb24gbXVzdCB1c2UgY29tbWVudE9wdGlvbnMgb3BlcmF0aW9uJykpIHJldHVybjsKICBjb25zdCBhdXRob3JwZXJtID0gYEAke2F1dGhvcn0vJHtwZXJtbGlua31gOwoKICB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