Market Smart Contract

in #steem-engine5 years ago

{"id":"ssc-mainnet1","json":{"contractName":"contract","contractAction":"update","contractPayload":{"name":"market","params":"","code":"LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLw0KLyogZ2xvYmFsIGFjdGlvbnMsIGFwaSAqLw0KY29uc3QgU1RFRU1fUEVHR0VEX1NZTUJPTCA9ICdTVEVFTVAnOw0KY29uc3QgU1RFRU1fUEVHR0VEX1NZTUJPTF9QUkVTSUNJT04gPSA4Ow0KY29uc3QgQ09OVFJBQ1RfTkFNRSA9ICdtYXJrZXQnOw0KDQpjb25zdCBnZXRNZXRyaWMgPSBhc3luYyAoc3ltYm9sKSA9PiB7DQogIGxldCBtZXRyaWMgPSBhd2FpdCBhcGkuZGIuZmluZE9uZSgnbWV0cmljcycsIHsgc3ltYm9sIH0pOw0KDQogIGlmIChtZXRyaWMgPT09IG51bGwpIHsNCiAgICBtZXRyaWMgPSB7fTsNCiAgICBtZXRyaWMuc3ltYm9sID0gc3ltYm9sOw0KICAgIG1ldHJpYy52b2x1bWUgPSAnMCc7DQogICAgbWV0cmljLnZvbHVtZUV4cGlyYXRpb24gPSAwOw0KICAgIG1ldHJpYy5sYXN0UHJpY2UgPSAnMCc7DQogICAgbWV0cmljLmxvd2VzdEFzayA9ICcwJzsNCiAgICBtZXRyaWMuaGlnaGVzdEJpZCA9ICcwJzsNCiAgICBtZXRyaWMubGFzdERheVByaWNlID0gJzAnOw0KICAgIG1ldHJpYy5sYXN0RGF5UHJpY2VFeHBpcmF0aW9uID0gMDsNCiAgICBtZXRyaWMucHJpY2VDaGFuZ2VTdGVlbSA9ICcwJzsNCiAgICBtZXRyaWMucHJpY2VDaGFuZ2VQZXJjZW50ID0gJzAnOw0KDQogICAgY29uc3QgbmV3TWV0cmljID0gYXdhaXQgYXBpLmRiLmluc2VydCgnbWV0cmljcycsIG1ldHJpYyk7DQogICAgcmV0dXJuIG5ld01ldHJpYzsNCiAgfQ0KDQogIHJldH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nQsIHN5bWJvbCwgYnV5T3JkZXIucXVhbnRpdHksICd1c2VyJyk7DQoNCiAgICAgICAgICBpZiAocmVzLmVycm9ycykgew0KICAgICAgICAgICAgYXBpLmRlYnVnKHJlcy5lcnJvcnMpOw0KICAgICAgICAgICAgYXBpLmRlYnVnKGBUWElEOiAke2FwaS50cmFuc2FjdGlvbklkfWApOw0KICAgICAgICAgICAgYXBpLmRlYnVnKGJ1eU9yZGVyLmFjY291bnQpOw0KICAgICAgICAgICAgYXBpLmRlYnVnKHN5bWJvbCk7DQogICAgICAgICAgICBhcGkuZGVidWcoYnV5T3JkZXIucXVhbnRpdHkpOw0KICAgICAgICAgIH0NCg0KICAgICAgICAgIC8vIHRyYW5zZmVyIHRoZSB0b2tlbnMgdG8gdGhlIHNlbGxlcg0KICAgICAgICAgIHJlcyA9IGF3YWl0IGFwaS50cmFuc2ZlclRva2VucyhhY2NvdW50LCBTVEVFTV9QRUdHRURfU1lNQk9MLCBxdHlUb2tlbnNUb1NlbmQsICd1c2VyJyk7DQoNCiAgICAgICAgICBpZiAocmVzLmVycm9ycykgew0KICAgICAgICAgICAgYXBpLmRlYnVnKHJlcy5lcnJvcnMpOw0KICAgICAgICAgICAgYXBpLmRlYnVnKGBUWElEOiAke2FwaS50cmFuc2FjdGlvbklkfWApOw0KICAgICAgICAgICAgYXBpLmRlYnVnKGFjY291bnQpOw0KICAgICAgICAgICAgYXBpLmRlYnVnKFNURUVNX1BFR0dFRF9TWU1CT0wpOw0KICAgICAgICAgICAgYXBpLmRlYnVnKHF0eVRva2Vuc1RvU2VuZCk7DQogICAgICAgICAgfQ0KDQogICAgICAgICAgY29uc3QgYnV5T3JkZXJ0b2tlbnNMb2NrZWQgPSBhcGkuQmlnTnVtYmVyKGJ1eU9yZGVyLnRva2Vuc0xvY2tlZCkNCiAgICAgICAgICAgIC5taW51cyhxdHlUb2tlbnNUb1NlbmQpDQogICAgICAgICAgICAudG9GaXhlZChTVEVFTV9QRUdHRURfU1lNQk9MX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FwaS5CaWdOdW1iZXIuUk9VTkRfRE9XTik7DQoNCiAgICAgICAgICAgIGlmIChhcGkuQmlnTnVtYmVyKHF0eVRva2Vuc1RvU2VuZCkubHRlKHNlbGxPcmRlci5xdWFudGl0eSkNCiAgICAgICAgICAgICAgJiYgYXBpLkJpZ051bWJlcihxdHlUb2tlbnNUb1NlbmQpLmd0KDApKSB7DQogICAgICAgICAgICAgIGlmIChhcGkuYXNzZXJ0KGFwaS5CaWdOdW1iZXIocXR5VG9rZW5zVG9TZW5kKS5ndCgwKQ0KICAgICAgICAgICAgICAgICYmIGFwaS5CaWdOdW1iZXIoc3RlZW1wUmVtYWluaW5nKS5ndCgwKSwgJ3RoZSBvcmRlciBjYW5ub3QgYmUgZmlsbGVkJykpIHsNCiAgICAgICAgICAgICAgICAvLyB0cmFuc2ZlciB0aGUgdG9rZW5zIHRvIHRoZSBidXllcg0KICAgICAgICAgICAgICAgIGxldCByZXMgPSBhd2FpdCBhcGkudHJhbnNmZXJUb2tlbnMoYXBpLnNlbmRlciwgc3ltYm9sLCBxdHlUb2tlbnNUb1NlbmQsICd1c2VyJyk7DQoNCiAgICAgICAgICAgICAgICBpZiAocmVzLmVycm9ycykgew0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKHJlcy5lcnJvcnMpOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKGBUWElEOiAke2FwaS50cmFuc2FjdGlvbklkfWApOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKGFwaS5zZW5kZXIpOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKHN5bWJvbCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcocXR5VG9rZW5zVG9TZW5kKTsNCiAgICAgICAgICAgICAgICB9DQoNCiAgICAgICAgICAgICAgICAvLyB0cmFuc2ZlciB0aGUgdG9rZW5zIHRvIHRoZSBzZWxsZXINCiAgICAgICAgICAgICAgICByZXMgPSBhd2FpdCBhcGkudHJhbnNmZXJUb2tlbnMoc2VsbE9yZGVyLmFjY291bnQsIFNURUVNX1BFR0dFRF9TWU1CT0wsIHN0ZWVtcFJlbWFpbmluZywgJ3VzZXInKTsNCg0KICAgICAgICAgICAgICAgIGlmIChyZXMuZXJyb3JzKSB7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcocmVzLmVycm9ycyk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoYFRYSUQ6ICR7YXBpLnRyYW5zYWN0aW9uSWR9YCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoc2VsbE9yZGVyLmFjY291bnQpOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKFNURUVNX1BFR0dFRF9TWU1CT0wpOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKHN0ZWVtcFJlbWFpbmluZyk7DQogICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgLy8gdXBkYXRlIHRoZSBzZWxsIG9yZGVyDQogICAgICAgICAgICAgICAgY29uc3QgcXR5TGVmdFNlbGxPcmRlciA9IGFwaS5CaWdOdW1iZXIoc2VsbE9yZGVyLnF1YW50aXR5KQ0KICAgICAgICAgICAgICAgICAgLm1pbnVzKHF0eVRva2Vuc1RvU2VuZCkNCiAgICAgICAgICAgICAgICAgIC50b0ZpeGVkKHRva2VuLnByZWNpc2lvbik7DQogICAgICAgICAgICAgICAgY29uc3QgbmJUb2tlbnNUb0ZpbGxPcmRlciA9IGFwaS5CaWdOdW1iZXIoc2VsbE9yZGVyLnByaWNlKQ0KICAgICAgICAgICAgICAgICAgLm11bHRpcGxpZWRCeShxdHlMZWZ0U2VsbE9yZGVyKQ0KICAgICAgICAgICAgICAgICAgLnRvRml4ZWQoU1RFRU1fUEVHR0VEX1NZTUJPTF9QUkVTSUNJT04pOw0KDQogICAgICAgICAgICAgICAgaWYgKGFwaS5CaWdOdW1iZXIocXR5TGVmdFNlbGxPcmRlcikuZ3QoMCkNCiAgICAgICAgICAgICAgICAgICYm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AgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0gZWxzZSBpZiAoYXBpLkJpZ051bWJlcihxdHlUb2tlbnNUb1NlbmQpLmd0KDApKSB7DQogICAgICAgICAgICAgIGxldCBxdHlTdGVlbXBUb1NlbmQgPSBhcGkuQmlnTnVtYmVyKHNlbGxPcmRlci5wcmljZSkNCiAgICAgICAgICAgICAgICAubXVsdGlwbGllZEJ5KHNlbGxPcmRlci5xdWFudGl0eSkNCiAgICAgICAgICAgICAgICAudG9GaXhlZChTVEVFTV9QRUdHRURfU1lNQk9MX1BSRVNJQ0lPTik7DQoNCiAgICAgICAgICAgICAgaWYgKGFwaS5CaWdOdW1iZXIocXR5U3RlZW1wVG9TZW5kKS5ndChzdGVlbXBSZW1haW5pbmcpKSB7DQogICAgICAgICAgICAgICAgcXR5U3RlZW1wVG9TZW5kID0gYXBpLkJpZ051bWJlcihzZWxsT3JkZXIucHJpY2UpDQogICAgICAgICAgICAgICAgICAubXVsdGlwbGllZEJ5KHNlbGxPcmRlci5xdWFudGl0eSkNCiAgICAgICAgICAgICAgICAgIC50b0ZpeGVkKFNURUVNX1BFR0dFRF9TWU1CT0xfUFJFU0lDSU9OLCBhcGkuQmlnTnVtYmVyLlJPVU5EX0RPV04pOw0KICAgICAgICAgICAgICB9DQoNCiAgICAgICAgICAgICAgaWYgKGFwaS5hc3NlcnQoYXBpLkJpZ051bWJlcihxdHlTdGVlbXBUb1NlbmQpLmd0KDApDQogICAgICAgICAgICAgICAgJiYgYXBpLkJpZ051bWJlcihzdGVlbXBSZW1haW5pbmcpLmd0KDApLCAndGhlIG9yZGVyIGNhbm5vdCBiZSBmaWxsZWQnKSkgew0KICAgICAgICAgICAgICAgIC8vIHRyYW5zZmVyIHRoZSB0b2tlbnMgdG8gdGhlIGJ1eWVyDQogICAgICAgICAgICAgICAgbGV0IHJlcyA9IGF3YWl0IGFwaS50cmFuc2ZlclRva2VucyhhcGkuc2VuZGVyLCBzeW1ib2wsIHNlbGxPcmRlci5xdWFudGl0eSwgJ3VzZXInKTsNCg0KICAgICAgICAgICAgICAgIGlmIChyZXMuZXJyb3JzKSB7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcocmVzLmVycm9ycyk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoYFRYSUQ6ICR7YXBpLnRyYW5zYWN0aW9uSWR9YCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoYXBpLnNlbmRlcik7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoc3ltYm9sKTsNCiAgICAgICAgICAgICAgICAgIGFwaS5kZWJ1ZyhzZWxsT3JkZXIucXVhbnRpdHkpOw0KICAgICAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgICAgIC8vIHRyYW5zZmVyIHRoZSB0b2tlbnMgdG8gdGhlIHNlbGxlcg0KICAgICAgICAgICAgICAgIHJlcyA9IGF3YWl0IGFwaS50cmFuc2ZlclRva2VucyhzZWxsT3JkZXIuYWNjb3VudCwgU1RFRU1fUEVHR0VEX1NZTUJPTCwgcXR5U3RlZW1wVG9TZW5kLCAndXNlcicpOw0KDQogICAgICAgICAgICAgICAgaWYgKHJlcy5lcnJvcnMpIHsNCiAgICAgICAgICAgICAgICAgIGFwaS5kZWJ1ZyhyZXMuZXJyb3JzKTsNCiAgICAgICAgICAgICAgICAgIGFwaS5kZWJ1ZyhgVFhJRDogJHthcGkudHJhbnNhY3Rpb25JZH1gKTsNCiAgICAgICAgICAgICAgICAgIGFwaS5kZWJ1ZyhzZWxsT3JkZXIuYWNjb3VudCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoU1RFRU1fUEVHR0VEX1NZTUJPTCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcocXR5U3RlZW1wVG9TZW5kKTsNCiAgICAgICAgICAgICAgICB9DQoNCiAgICAgICAgICAgICAgICAvLyByZW1vdmUgdGhlIHNlbGwgb3JkZXINCiAgICAgICAgICAgICAgICBhd2FpdCBhcGkuZGIucmV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ICAgICAgICAgICAgIC8vIHRyYW5zZmVyIHRoZSB0b2tlbnMgdG8gdGhlIGJ1eWVyDQogICAgICAgICAgICAgICAgbGV0IHJlcyA9IGF3YWl0IGFwaS50cmFuc2ZlclRva2VucyhidXlPcmRlci5hY2NvdW50LCBzeW1ib2wsIHRva2Vuc1JlbWFpbmluZywgJ3VzZXInKTsNCg0KICAgICAgICAgICAgICAgIGlmIChyZXMuZXJyb3JzKSB7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcocmVzLmVycm9ycyk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoYFRYSUQ6ICR7YXBpLnRyYW5zYWN0aW9uSWR9YCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoYnV5T3JkZXIuYWNjb3VudCk7DQogICAgICAgICAgICAgICAgICBhcGkuZGVidWcoc3ltYm9sKTsNCiAgICAgICAgICAgICAgICAgIGFwaS5kZWJ1Zyh0b2tlbnNSZW1haW5pbmcpOw0KICAgICAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgICAgIC8vIHRyYW5zZmVyIHRoZSB0b2tlbnMgdG8gdGhlIHNlbGxlcg0KICAgICAgICAgICAgICAgIHJlcyA9IGF3YWl0IGFwaS50cmFuc2ZlclRva2VucyhhcGkuc2VuZGVyLCBTVEVFTV9QRUdHRURfU1lNQk9MLCBxdHlUb2tlbnNUb1NlbmQsICd1c2VyJyk7DQoNCiAgICAgICAgICAgICAgICBpZiAocmVzLmVycm9ycykgew0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKHJlcy5lcnJvcnMpOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKGBUWElEOiAke2FwaS50cmFuc2FjdGlvbklkfWApOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKGFwaS5zZW5kZXIpOw0KICAgICAgICAgICAgICAgICAgYXBpLmRlYnVnKFNURUVNX1BFR0dFRF9TWU1CT0wpOw0KICAgICAgICAgICAgICAgICAgYXBpLm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QogICAgICAgICAgICB9DQoNCiAgICAgICAgICAgIGluYyArPSAxOw0KICAgICAgICAgIH0NCg0KICAgICAgICAgIG9mZnNldCArPSAxMDAwOw0KDQogICAgICAgICAgaWYgKGFwaS5CaWdOdW1iZXIodG9rZW5zUmVtYWluaW5nKS5ndCgwKSkgew0KICAgICAgICAgICAgLy8gZ2V0IHRoZSBvcmRlcnMgdGhhdCBtYXRjaCB0aGUgc3ltYm9sIGFuZCB0aGUgcHJpY2UNCiAgICAgICAgICAgIGJ1eU9yZGVyQm9vayA9IGF3YWl0IGFwaS5kYi5maW5kKCdidXlCb29rJywgew0KICAgICAgICAgICAgICBzeW1ib2wsDQogICAgICAgICAgICB9LCAxMDAwLCBvZmZzZXQsDQogICAgICAgICAgICBbDQogICAgICAgICAgICAgIHsgaW5kZXg6ICdwcmljZURlYycsIGRlc2NlbmRpbmc6IHRydWUgfSwNCiAgICAgICAgICAgICAgeyBpbmRleDogJ19pZCcsIGRlc2NlbmRpbmc6IGZhbHNlIH0sDQogICAgICAgICAgICBdKTsNCiAgICAgICAgICB9DQogICAgICAgIH0gd2hpbGUgKGJ1eU9yZGVyQm9vay5sZW5ndGggPiAwICYmIGFwaS5CaWdOdW1iZXIodG9rZW5zUmVtYWluaW5nKS5ndCgwKSk7DQoNCiAgICAgICAgLy8gc2VuZCBiYWNrIHRoZSByZW1haW5pbmcgdG9rZW5zDQogICAgICAgIGlmIChhcGkuQmlnTnVtYmVyKHRva2Vuc1JlbWFpbmluZykuZ3QoMCkpIHsNCiAgICAgICAgICBhd2FpdCBhcGkudHJhbnNmZXJUb2tlbnMoYXBpLnNlbmRlciwgc3ltYm9sLCB0b2tlbnNSZW1haW5pbmcsICd1c2VyJyk7DQogICAgICAgIH0NCg0KICAgICAgICBpZiAoYXBpLkJpZ051bWJlcih2b2x1bWVUcmFkZWQpLmd0KDApKSB7DQogICAgICAgICAgYXdhaXQgdXBkYXRlVm9sdW1lTWV0cmljKHN5bWJvbCwgdm9sdW1lVHJhZGVkKTsNCiAgICAgICAgfQ0KICAgICAgICBhd2FpdCB1cGRhdGVBc2tNZXRyaWMoc3ltYm9sKTsNCiAgICAgICAgYXdhaXQgdXBkYXRlQmlkTWV0cmljKHN5bWJvbCk7DQogICAgICB9DQogICAgfQ0KICB9DQp9Ow0K"}}}

Coin Marketplace

STEEM 0.19
TRX 0.18
JST 0.032
BTC 88139.36
ETH 3066.37
USDT 1.00
SBD 2.76