Market Smart Contract

in #steem-engine6 years ago (edited)

{
"id": "ssc-mainnet1",
"json": {
"contractName": "contract",
"contractAction": "update",
"contractPayload": {
"name": "market",
"params": "",
"code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBnbG9iYWwgYWN0aW9ucywgYXBpICovCmNvbnN0IFNURUVNX1BFR0dFRF9TWU1CT0wgPSAnU1RFRU1QJzsKY29uc3QgU1RFRU1fUEVHR0VEX1NZTUJPTF9QUkVTSUNJT04gPSA4Owpjb25zdCBDT05UUkFDVF9OQU1FID0gJ21hcmtldCc7Cgpjb25zdCBwcm9jZXNzQnV5T3JkZXJzID0gYXN5bmMgKHRva2VucyA9ICcwJywgaW5kZXggPSAwKSA9PiB7CiAgbGV0IHJlcyA9IGF3YWl0IGFwaS5kYi5maW5kKCdidXlCb29rJywge30sIDEwMDAsIGluZGV4KTsKCiAgaWYgKHJlcy5sZW5ndGggPD0gMCkgewogICAgcmVzID0gYXdhaXQgYXBpLmRiLmZpbmRJblRhYmxlKAogICAgICAndG9rZW5zJywKICAgICAgJ2NvbnRyYWN0c0JhbGFuY2VzJywKICAgICAgeyBzeW1ib2w6IFNURUVNX1BFR0dFRF9TWU1CT0wgfSwKICAgICAgMTAwMCwKICAgICAgMCwKICAgICk7CiAgICBpZiAocmVzLmxlbmd0aCA+IDApIHsKICAgICAgY29uc3QgZGlmZiA9IGFwaS5CaWdOdW1iZXIocmVzWzBdLmJhbGFuY2UpCiAgICAgICAgLm1pbnVzKHRva2VucykKICAgICAgICAudG9GaXhlZChTVEVFTV9QRUdHRURfU1lNQk9MX1BSRVNJQ0lPTik7CgogICAgICBhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoJ3RlbXAnKTsKICAgICAgY29uc3QgdGVtcCA9IHt9OwogICAgICB0ZW1wLmRpZmYgPSBkaWZmOwogICAgICBhd2FpdCBhcGkuZGIuaW5zZXJ0KCd0ZW1wJywgdGVtcCk7CiAgICB9CiAgfSB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MgPSBhcGkuQmlnTnVtYmVyKG5ldyBEYXRlKGAke2FwaS5zdGVlbUJsb2NrVGltZXN0YW1wfS4wMDBaYCkuZ2V0VGltZSgpKQogICAgICAgICAgICAuZGl2aWRlZEJ5KDEwMDApCiAgICAgICAgICAgIC50b051bWJlcigpOwoKICAgICAgICAgIC8vIG9yZGVyCiAgICAgICAgICBjb25zdCBvcmRlciA9IHt9OwoKICAgICAgICAgIG9yZGVyLnR4SWQgPSBhcGkudHJhbnNhY3Rpb25JZDsKICAgICAgICAgIG9yZGVyLnRpbWVzdGFtcCA9IHRpbWVzdGFtcFNlYzsKICAgICAgICAgIG9yZGVyLmFjY291bnQgPSBhcGkuc2VuZGVyOwogICAgICAgICAgb3JkZXIuc3ltYm9sID0gc3ltYm9sOwogICAgICAgICAgb3JkZXIucXVhbnRpdHkgPSBxdWFudGl0eTsKICAgICAgICAgIG9yZGVyLnByaWNlID0gcHJpY2U7CiAgICAgICAgICBvcmRlci50b2tlbnNMb2NrZWQgPSBuYlRva2Vuc1RvTG9jazsKICAgICAgICAgIG9yZGVyLmV4cGlyYXRpb24gPSBleHBpcmF0aW9uID09PSB1bmRlZmluZWQgfHwgZXhwaXJhdGlvbiA+IDI1OTIwMDAKICAgICAgICAgICAgPyB0aW1lc3RhbXBTZWMgKyAyNTkyMDAwCiAgICAgICAgICAgIDogdGltZXN0YW1wU2VjICsgZXhwaXJhdGlvbjsKCiAgICAgICAgICBjb25zdCBvcmRlckluRGIgPSBhd2FpdCBhcGkuZGIuaW5zZXJ0KCdidXlCb29rJywgb3JkZXIpOwoKICAgICAgICAgIGF3YWl0IGZpbmRNYXRjaGluZ1NlbGxPcmRlcnMob3JkZXJJbkRiLCB0b2tlbi5wcmVjaXNpb24pOwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KfTsKCmFjdGlvbnMuc2VsbCA9IGFzeW5jIChwYXlsb2FkKSA9PiB7CiAgY29uc3QgewogICAgc3ltYm9sLAogICAgcXVhbnRpdHksCiAgIC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ST1VORF9ET1dOKTsKICAgICAgICB9CgogICAgICAgIGlmIChhcGkuYXNzZXJ0KGFwaS5CaWdOdW1iZXIocXR5VG9rZW5zVG9TZW5kKS5ndCgwKQogICAgICAgICAgJiYgYXBpLkJpZ051bWJlcihidXlPcmRlci5xdWFudGl0eSkuZ3QoMCksICd0aGUgb3JkZXIgY2Fubm90IGJlIGZpbGxlZCcpKSB7CiAgICAgICAgICAvLyB0cmFuc2ZlciB0aGUgdG9rZW5zIHRvIHRoZSBidXllcgogICAgICAgICAgbGV0IHJlcyA9IGF3YWl0IGFwaS50cmFuc2ZlclRva2VucyhhY2NvdW50LCBzeW1ib2wsIHNlbGxPcmRlci5xdWFudGl0eSwgJ3VzZXInKTsKCiAgICAgICAgICBpZiAocmVzLmVycm9ycykgewogICAgICAgICAgICBhcGkuZGVidWcocmVzLmVycm9ycyk7CiAgICAgICAgICAgIGFwaS5kZWJ1ZyhgVFhJRDogJHthcGkudHJhbnNhY3Rpb25JZH1gKTsKICAgICAgICAgICAgYXBpLmRlYnVnKGFjY291bnQpOwogICAgICAgICAgICBhcGkuZGVidWcoc3ltYm9sKTsKICAgICAgICAgICAgYXBpLmRlYnVnKHNlbGxPcmRlci5xdWFudGl0eSk7CiAgICAgICAgICB9CgogICAgICAgICAgLy8gdHJhbnNmZXIgdGhlIHRva2VucyB0byB0aGUgc2VsbGVyCiAgICAgICAgICByZXMgPSBhd2FpdCBhcGkudHJhbnNmZXJUb2tlbnMoc2VsbE9yZGVyLmFjY291bnQsIFNURUVNX1BFR0dFRF9TWU1CT0wsIHF0eVRva2Vuc1RvU2VuZCwgJ3VzZXInKTsKCiAgICAgICAgICBpZiAocmVzLmVycm9ycykgewogICAgICAgICAgICBhcGkuZGVidWcocmVzLmVycm9ycyk7CiAgICAgICAgICAgIGFwaS5kZWJ1ZyhgVFhJRDogJHthcGkudHJhbnNhY3Rpb25JZH1gKTsKICAgICAgICAgICAgYXBpLmRlYnVnKHNlbGxPcmRlci5hY2NvdW50K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FkZSk7CiAgYXdhaXQgdXBkYXRlUHJpY2VNZXRyaWNzKHN5bWJvbCwgcHJpY2UpOwp9OwoKY29uc3QgY291bnREZWNpbWFscyA9IHZhbHVlID0+IGFwaS5CaWdOdW1iZXIodmFsdWUpLmRwKCk7Cg=="
}
}
}

Sort:  

Congratulations @steemsc! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!