You are viewing a single comment's thread from:

RE: Test title

in #topic16 years ago

{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "smmt",
"code": "Y29uc3QgVE9LRU5TWU1CT0wgPSAnU01NVCc7CmFjdGlvbnMuY3JlYXRlU1NDID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBkYi5jcmVhdGVUYWJsZSgnYmFsYW5jZXMnKTsKICBsZXQgcmV3YXJkcyA9IGRiLmNyZWF0ZVRhYmxlKCdyZXdhcmRzJyk7CiAgcmV3YXJkcy5pbnNlcnQoewogICAgJ3BlbmRpbmdSZXdhcmRzJzogMCwKICAgICdyZXdhcmRzRGlzdHJpYnV0aW9uSW50ZXJ2YWwnOiAzMDAwMCwKICAgICdsYXN0QmxvY2tSZXdhcmQnOiAwLAogICAgJ3Rva2VuSXNzdWFuY2VSYXRlJzogMSwKICAgICduZXh0SGFsdmluZyc6IDUwMDAwMCwKICAgICdiZW5lZmljaWFyaWVzJzogWydzdGVlbW1vbnN0ZXJzJywgJ2hhcnBhZ29uJ10KICB9KQp9CgphY3Rpb25zLnVwZGF0ZVJld2FyZHNEaXN0cmlidXRpb25JbnRlcnZhbCA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgaWYgKHNlbmRlciAhPT0gb3duZXIpIHJldHVybjsKCiAgY29uc3QgeyBuYkJsb2NrcyB9ID0gcGF5bG9hZDsKCiAgaWYgKE51bWJlci5pc0ludGVnZXIobmJCbG9ja3MpKSB7CiAgICBsZXQgcmV3YXJkcyA9IGRiLmdldFRhYmxlKCdyZXdhcmRzJyk7CiAgICBsZXQgcmVjID0gcmV3YXJkcy5maW5kT25lKHt9KTsKICAgIHJlYy5yZXdhcmRzRGlzdHJpYnV0aW9uSW50ZXJ2YWwgPSBuYkJsb2NrczsKICAgIHJld2FyZHMudXBkYXRlKHJlYyk7CiAgfQp9CgphY3Rpb25zLnVwZGF0ZUJlbmVmaWNpYXJpZX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1ZSkgPT09IHZhbHVlKSByZXR1cm4gMDsKICByZXR1cm4gdmFsdWUudG9TdHJpbmcoKS5zcGxpdCgnLicpWzFdLmxlbmd0aCB8fCAwOwp9"
}
}
}

Sort:  

{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "token",
"contractAction": "create",
"contractPayload": {
"symbol": "SMMKT",
"precision": 3,
"maxSupply": 1000000
}
}
}

{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "smmkt",
"code": "Y29uc3QgVE9LRU5TWU1CT0wgPSAnU01NS1QnOwphY3Rpb25zLmNyZWF0ZVNTQyA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgZGIuY3JlYXRlVGFibGUoJ2JhbGFuY2VzJyk7CiAgbGV0IHJld2FyZHMgPSBkYi5jcmVhdGVUYWJsZSgncmV3YXJkcycpOwogIHJld2FyZHMuaW5zZXJ0KHsKICAgICdwZW5kaW5nUmV3YXJkcyc6IDAsCiAgICAncmV3YXJkc0Rpc3RyaWJ1dGlvbkludGVydmFsJzogMzAwMDAsCiAgICAnbGFzdEJsb2NrUmV3YXJkJzogcmVmU3RlZW1CbG9ja051bWJlciwKICAgICd0b2tlbklzc3VhbmNlUmF0ZSc6IDEsCiAgICAnbmV4dEhhbHZpbmcnOiA1MDAwMDAsCiAgICAnYmVuZWZpY2lhcmllcyc6IFsnc21tYXJrZXR0b2tlbiddCiAgfSkKfQoKYWN0aW9ucy51cGRhdGVSZXdhcmRzRGlzdHJpYnV0aW9uSW50ZXJ2YWwgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGlmIChzZW5kZXIgIT09IG93bmVyKSByZXR1cm47CgogIGNvbnN0IHsgbmJCbG9ja3MgfSA9IHBheWxvYWQ7CgogIGlmIChOdW1iZXIuaXNJbnRlZ2VyKG5iQmxvY2tzKSkgewogICAgbGV0IHJld2FyZHMgPSBkYi5nZXRUYWJsZSgncmV3YX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