Test body
Test Body 2
test comment
test comment 2
edited comment
test reply
test comment 5
It's hard to say, but The ENIAC is regarded as the first 'real' computer. It was developed at University of Pennsylvania in 1946.
another comment
yes, marx had made some interesting observations.
test
test 6
test 7 test 73 test 75
test !zè§!èz
etrtrt
post test comment
***test
test dffdgerter
##STEEMCONTRACTSBEGIN##CONTRACTNAME##CONTRACTACTION##PAYLOAD##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract'##hello##{ "name": "Harpagon" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract##hello##{ "name": "Harpagon" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##if(payload&&payload.name&&'string'==typeof payload.name){const a='Hello '+payload.name;db.greetings=db.greetings?db.greetings:db.greetings=[],db.greetings.push(a)}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract", "code": "if(payload&&payload.name&&'string'==typeof payload.name){const a='Hello '+payload.name;db.greetings=db.greetings?db.greetings:db.greetings=[],db.greetings.push(a)}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(a){const{username:b}=a;if(b&&'string'==typeof b){let c=db.getTable('users'),d=db.findJsonPath(c,$..[?(@.id == '\${sender}')]);if(d);else{const e={id:sender,username:b};c.push(e)}}},actions.updateUser=function(a){const{username:b}=a;if(b&&'string'==typeof b){let c=db.getTable('users'),d=db.findJsonPath(c,$..[?(@.id == '\${sender}')]);d&&(d.username=b)}},actions.removeUser=function(a){if(sender==owner){const{userId:b}=a;if(b&&'string'==typeof b){let c=db.getTable('users');const d=c.findIndex(e=>e.id===b);-1!=d&&c.splice(d,1)}}};"}##STEEMCONTRACTSEND##
$..[?(@.id == '\${sender}')]
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,`$..[?(@.id=='${sender}')]`);if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,`$..[?(@.id=='${sender}')]`);if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "account", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "token", "code": "YWN0aW9ucy5jcmVhdGV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FN1cHBseSBtdXN0IGJlIHBvc2l0aXZlJykpIHsKICAgICAgICAgICAgbGV0IHRva2VucyA9IGRiLmdldFRhYmxlKCd0b2tlbnMnKTsKICAgIAogICAgICAgICAgICAvLyBjaGVjayBpZiB0aGUgdG9rZW4gYWxyZWFkeSBleGlzdHMKICAgICAgICAgICAgbGV0IHRva2VuID0gdG9rZW5zLmZpbmRPbmUoeyBzeW1ib2wgfSk7CiAgICAKICAgICAgICAgICAgaWYgKGFzc2VydCh0b2tlbiA9PT0gbnVsbCwgJ3N5bWJvbCBhbHJlYWR5IGV4aXN0cycpKSB7IAogICAgICAgICAgICAgIGNvbnN0IG5ld1Rva2VuID0gewogICAgICAgICAgICAgICAgJ2lzc3Vlcic6IHNlbmRlciwKICAgICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICAgIHByZWNpc2lvbiwKICAgICAgICAgICAgICAgIG1heFN1cHBseSwKICAgICAgICAgICAgICAgICdzdXBwbHknOiAwCiAgICAgICAgICAgICAgfTsKICAgICAgICAgIAogICAgICAgICAgICAgIHRva2Vucy5pbnNlcnQobmV3VG9rZW4pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMuaXNzdWUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5IH0gPSBwYXlsb2FkOwogICAgCiAgICAgIGlmICh0byAmJiB0eXBlb2YgdG8gPT09ICdzdHJpbmcnCiAgICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bWJvbCA9PT0gJ3N0cmluZycKICAgICAgICAgICYmIHF1YW50aXR5ICYmIHR5cGVvZiBxdWFudGl0eSA9PT0gJ251bWJlcicpIHsKICAgICAgICAKICAgICAgICBsZXQgdG9rZW5zID0gZGIuZ2V0VGFibGUoJ3Rva2VucycpOwogICAgICAgIGxldCB0b2tlbiA9IHRva2Vucy5maW5kT25lKHs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lcmlmaWNhdGlvbiwgbGV0J3Mgbm93IGlzc3VlIHRoZSB0b2tlbnMKICAgIAogICAgICAgICAgICAgIHRva2VuLnN1cHBseSA9IGNhbGN1bGF0ZUJhbGFuY2UodG9rZW4uc3VwcGx5LCBxdWFudGl0eSwgdG9rZW4ucHJlY2lzaW9uLCB0cnVlKTsKICAgICAgICAgICAgICB0b2tlbnMudXBkYXRlKHRva2VuKTsKICAgICAgICAgICAgICAKICAgICAgICAgICAgICBhZGRCYWxhbmNlKHRva2VuLmlzc3VlciwgdG9rZW4sIHF1YW50aXR5KTsKICAgIAogICAgICAgICAgICAgIGlmKHRvICE9PSB0b2tlbi5pc3N1ZXIpIHsKICAgICAgICAgICAgICAgIGFjdGlvbnMudHJhbnNmZXIocGF5bG9hZCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMudHJhbnNmZXIgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5IH0gPSBwYXlsb2FkOwogICAgCiAgICAgIGlmICh0byAmJiB0eXBlb2YgdG8gPT09ICdzdHJpbmcnCiAgICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bWJvbCA9PT0gJ3N0cmluZycKICAgICAgICAgICYmIHF1YW50aXR5ICYmIHR5cGVvZiBxdWFudGl0eSA9PT0gJ251bWJlcicpIHsKICAgIAogICAgICAgIGlmIChhc3NlcnQodG8gIT09IHNlbmRlciwgJ2Nhbm5vdCB0cmFuc2ZlciB0byBzZWxmJykpIHsKICAgICAgICAgIGxldCBhY2NvdW50ID0gZGIuZmluZE9uZUluVGFibGUoJ2FjY291bnQnLCAnYWNjb3VudHMnLCB7ICdpZCc6IHRvIH0pOwogICAgCiAgICAgICAgICAvLyB0aGUgYWNjb3VudCBtdXN0IGhhdmUgYmVlbiByZWdpc3RlcmVkIGJlZm9yZQogICAgICAgICAgaWYgKGFzc2VydChhY2NvdW50ICE9PSBudWxsLCAndG8gYWNjb3VudCBkb2VzIG5vdCBleGlzdCcpKSB7CiAgICAgICAgICAgIGxldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAgICAgICAgIGxldCB0b2tlbiA9IHRva2Vucy5maW5kT25lKHsgc3ltYm9sIH0pOwogICAgCiAgICAgICAgICAgIC8vIHRoZSBzeW1ib2wgbXVzdCBleGlzdAogICAgICAgICAgICAvLyB0aGVuIHdlIG5lZWQgdG8gY2hlY2sgdGhhdCB0aGUgcXVhbnRpdHkgaXMgY29ycmVjdAogICAgICAgICAgICBpZiAoYXNzZXJ0KHRva2VuICE9PSBudWxsLCAnc3ltYm9sIGRvZXMgbm90IGV4aXN0JykKICAgICAgICAgICAgICAgICYmIGFzc2VydChjb3VudERlY2ltYWxzKHF1YW50aXR5KSA8PSB0b2tlbi5wcmVjaXNpb24sICdzeW1ib2wgcHJlY2lzaW9uIG1pc21hdGNoJykKICAgICAgICAgICAgICAgICYmIGFzc2VydChxdWFudGl0eSA+IDAsICdtdXN0IHRyYW5zZmVyIHBvc2l0aXZlIHF1YW50aXR5JykpIHsKICAgICAgICAgICAgICAKICAgICAgICAgICAgICBpZiAoc3ViQmFsYW5jZShzZW5kZXIsIHRva2VuLCBxdWFudGl0eSkpIHsKICAgICAgICAgICAgICAgIGFkZEJhbGFuY2UodG8sIHRva2VuLCBxdWFudGl0eSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGxldCBzdWJCYWxhbmNlID0gZnVuY3Rpb24gKGFjY291bnQsIHRva2VuLCBxdWFudGl0eSkgewogICAgICBsZXQgYmFsYW5jZXMgPSBkYi5nZXRUYWJsZSgnYmFsYW5jZXMnKTsKICAgICAgbGV0IGJhbGFuY2UgPSBiYWxhbmNlcy5maW5kT25lKHsgYWNjb3VudCwg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FsYW5jZXMuaW5zZXJ0KGJhbGFuY2UpOwogICAgICB9IGVsc2UgewogICAgICAgIGJhbGFuY2UuYmFsYW5jZSA9IGNhbGN1bGF0ZUJhbGFuY2UoYmFsYW5jZS5iYWxhbmNlLCBxdWFudGl0eSwgdG9rZW4ucHJlY2lzaW9uLCB0cnVlKTsKICAgIAogICAgICAgIGJhbGFuY2VzLnVwZGF0ZShiYWxhbmNlKTsKICAgICAgfQogICAgfQoKICAgIGxldCBjYWxjdWxhdGVCYWxhbmNlID0gZnVuY3Rpb24gKGJhbGFuY2UsIHF1YW50aXR5LCBwcmVjaXNpb24sIGFkZCkgewogICAgICBpZiAocHJlY2lzaW9uID09PSAwKSB7CiAgICAgICAgcmV0dXJuIGFkZCA/IGJhbGFuY2UgKyBxdWFudGl0eSA6IGJhbGFuY2UgLSBxdWFudGl0eSAKICAgICAgfQoKICAgICAgbGV0IHJhdGUgPSBNYXRoLnBvdygxMCwgcHJlY2lzaW9uKTsKICAgICAgbGV0IHRtcFF0eSA9IHF1YW50aXR5ICogcmF0ZTsKICAgICAgbGV0IHRtcEJhbGFuY2U9IGJhbGFuY2UgKiByYXRlOwoKICAgICAgcmV0dXJuIGFkZCA/ICh0bXBCYWxhbmNlICsgdG1wUXR5KSAvIHJhdGUgOiAodG1wQmFsYW5jZSAtIHRtcFF0eSkgLyByYXRlOwogICAgfQogICAgCiAgICBsZXQgY291bnREZWNpbWFscyA9IGZ1bmN0aW9uICh2YWx1ZSkgewogICAgICBpZihNYXRoLmZsb29yKHZhbHVlKSA9PT0gdmFsdWUpIHJldHVybiAwOwogICAgICByZXR1cm4gdmFsdWUudG9TdHJpbmcoKS5zcGxpdCgnLicpWzFdLmxlbmd0aCB8fCAwOyAKICAgIH0=" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "account2", "contractAction": "register", "contractPayload": {} } }
{ "id": "ssc-b8923f70-c1f7-497f-961g", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "account", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961g", "json": { "contractName": "account", "contractAction": "register", "contractPayload": {} } }
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "account", "contractAction": "register", "contractPayload": {} } }
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "token", "contractAction": "create", "contractPayload": { "symbol": "PKTC", "precision": 0, "maxSupply": 1000000 } } }
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "token", "contractAction": "issue", "contractPayload": { "symbol": "PKTC", "to": "harpagon", "quantity": 100 } } }
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "token", "contractAction": "issue", "contractPayload": { "symbol": "PKTC", "to": "harpagon", "quantity": 900 } } }
{ "id": "ssc-b8923f70-c1f7-497f-961g", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "token", "code": "YWN0aW9ucy5jcmVhdGVTU0M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VuY3Rpb24gKHZhbHVlKSB7CiAgaWYgKE1hdGguZmxvb3IodmFsdWUpID09PSB2YWx1ZSkgcmV0dXJuIDA7CiAgcmV0dXJuIHZhbHVlLnRvU3RyaW5nKCkuc3BsaXQoJy4nKVsxXS5sZW5ndGggfHwgMDsKfQ==" } } }
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user){}else{const newUser={"id":sender,"username":username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==="string"){let users=db.getTable("users");const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": 'actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user){}else{const newUser={"id":sender,"username":username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==="string"){let users=db.getTable("users");const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}'}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,'$..[?(@.id == ''+sender+'')]');if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,'$..[?(@.id == ''+sender+'')]');if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "YWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgIGlmICh1c2VybmFtZSAmJiB0eXBlb2YgdXNlcm5hbWUgPT09ICdzdHJpbmcnKXsNCg0KICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgIGxldCB1c2VyID0gZGIuZmluZEpzb25QYXRoKHVzZXJzLCBgJC4uWz8oQC5pZCA9PSAnXCR7c2VuZGVyfScpXWApOw0KDQogICAgICBpZiAodXNlcikgew0KICAgICAgICAvLyB1c2VyIGFscmVhZHkgZXhpc3RzDQogICAgICB9IGVsc2Ugew0KICAgICAgICBjb25zdCBuZXdVc2VyID0gew0KICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAndXNlcm5hbWUnOiB1c2VybmFtZQ0KICAgICAgICB9Ow0KICAgICAgICB1c2Vycy5wdXNoKG5ld1VzZXIpOw0KICAgICAgfQ0KICAgIH0NCiAgfQ0KDQogIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgY29uc3QgeyB1c2VybmFtZSB9ID0gcGF5bG9hZDsNCiAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgbGV0IHVzZXIgPSBkYi5maW5kSnNvblBhdGgodXNlcnMsIGAkLi5bPyhALmlkID09ICdcJHtzZW5kZXJ9JyldYCk7DQogICAgICBpZiAodXNlcikNCiAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgIH0NCiAgfQ0KDQogIGFjdGlvbnMucmVtb3ZlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgaWYgKHNlbmRlciAhPSBvd25lcikgcmV0dXJuOw0KICAgIA0KICAgIGNvbnN0IHsgdXNlcklkIH0gPSBwYXlsb2FkOw0KDQogICAgaWYgKHVzZXJJZCAmJiB0eXBlb2YgdXNlcklkID09PSAnc3RyaW5nJyl7DQogICAgICBsZXQgdXNlcnMgPSBkYi5nZXRUYWJsZSgndXNlcnMnKTsNCiAgICAgIGNvbnN0IGluZGV4ID0gdXNlcnMuZmluZEluZGV4KHVzZXIgPT4gdXNlci5pZCA9PT0gdXNlcklkKTsNCiAgICAgIGlmIChpbmRleCAhPSAtMSkNCiAgICAgICAgdXNlcnMuc3BsaWNlKGluZGV4LCAxKTsNCiAgICB9DQogIH0="}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "users_contract", "code": "YWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgew0KICAgICAgZGIuY3JlYXRlVGFibGUoJ3VzZXJzJyk7DQogICAgfQ0KDQogICAgYWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICAgIGNvbnN0IHsgdXNlcm5hbWUgfSA9IHBheWxvYWQ7DQogICAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgICAgbGV0IHVzZXIgPSB1c2Vycy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOw0KDQogICAgICAgIGlmICh1c2VyID09PSBudWxsKSB7DQogICAgICAgICAgY29uc3QgbmV3VXNlciA9IHsNCiAgICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAgICd1c2VybmFtZSc6IHVzZXJuYW1lLA0KICAgICAgICAgICAgJ3ZlcmlmaWVkJzogZmFsc2UsDQogICAgICAgICAgfTsNCg0KICAgICAgICAgIHVzZXJzLmluc2VydChuZXdVc2VyKTsNCiAgICAgICAgICBlbWl0KCduZXdVc2VyQ3JlYXRlZCcsIG5ld1VzZXIpOw0KICAgICAgICB9IA0KICAgICAgfQ0KICAgIH0NCg0KICAgIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgICAgaWYgKHVzZXJuYW1lICYmIHR5cGVvZiB1c2VybmFtZSA9PT0gJ3N0cmluZycpew0KDQogICAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgICBsZXQgdXNlciA9IHVzZXJzLmZpbmRPbmUoeyAnaWQnOiBzZW5kZXIgfSk7DQogICAgICAgIGlmICh1c2VyKSB7DQogICAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgICAgICAgIHVzZXJzLnVwZGF0ZSh1c2VyKTsNCiAgICAgICAgfQ0KICAgICAgfQ0KICAgIH0="##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##users_contract##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "users_contract", "code": "YWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgew0KICAgICAgZGIuY3JlYXRlVGFibGUoJ3VzZXJzJyk7DQogICAgfQ0KDQogICAgYWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICAgIGNvbnN0IHsgdXNlcm5hbWUgfSA9IHBheWxvYWQ7DQogICAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgICAgbGV0IHVzZXIgPSB1c2Vycy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOw0KDQogICAgICAgIGlmICh1c2VyID09PSBudWxsKSB7DQogICAgICAgICAgY29uc3QgbmV3VXNlciA9IHsNCiAgICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAgICd1c2VybmFtZSc6IHVzZXJuYW1lLA0KICAgICAgICAgICAgJ3ZlcmlmaWVkJzogZmFsc2UsDQogICAgICAgICAgfTsNCg0KICAgICAgICAgIHVzZXJzLmluc2VydChuZXdVc2VyKTsNCiAgICAgICAgICBlbWl0KCduZXdVc2VyQ3JlYXRlZCcsIG5ld1VzZXIpOw0KICAgICAgICB9IA0KICAgICAgfQ0KICAgIH0NCg0KICAgIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgICAgaWYgKHVzZXJuYW1lICYmIHR5cGVvZiB1c2VybmFtZSA9PT0gJ3N0cmluZycpew0KDQogICAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgICBsZXQgdXNlciA9IHVzZXJzLmZpbmRPbmUoeyAnaWQnOiBzZW5kZXIgfSk7DQogICAgICAgIGlmICh1c2VyKSB7DQogICAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgICAgICAgIHVzZXJzLnVwZGF0ZSh1c2VyKTsNCiAgICAgICAgfQ0KICAgICAgfQ0KICAgIH0="}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "users_test_contract", "code": "YWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgew0KICAgICAgZGIuY3JlYXRlVGFibGUoJ3VzZXJzJyk7DQogICAgfQ0KDQogICAgYWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICAgIGNvbnN0IHsgdXNlcm5hbWUgfSA9IHBheWxvYWQ7DQogICAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgICAgbGV0IHVzZXIgPSB1c2Vycy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOw0KDQogICAgICAgIGlmICh1c2VyID09PSBudWxsKSB7DQogICAgICAgICAgY29uc3QgbmV3VXNlciA9IHsNCiAgICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAgICd1c2VybmFtZSc6IHVzZXJuYW1lLA0KICAgICAgICAgICAgJ3ZlcmlmaWVkJzogZmFsc2UsDQogICAgICAgICAgfTsNCg0KICAgICAgICAgIHVzZXJzLmluc2VydChuZXdVc2VyKTsNCiAgICAgICAgICBlbWl0KCduZXdVc2VyQ3JlYXRlZCcsIG5ld1VzZXIpOw0KICAgICAgICB9IA0KICAgICAgfQ0KICAgIH0NCg0KICAgIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgICAgaWYgKHVzZXJuYW1lICYmIHR5cGVvZiB1c2VybmFtZSA9PT0gJ3N0cmluZycpew0KDQogICAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgICBsZXQgdXNlciA9IHVzZXJzLmZpbmRPbmUoeyAnaWQnOiBzZW5kZXIgfSk7DQogICAgICAgIGlmICh1c2VyKSB7DQogICAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgICAgICAgIHVzZXJzLnVwZGF0ZSh1c2VyKTsNCiAgICAgICAgfQ0KICAgICAgfQ0KICAgIH0="}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##users_test_contract##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
{ "id": "ssc-b8923f70-c1f7-497f-961d", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "account2", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961l", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "account", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961l", "json": { "contractName": "account", "contractAction": "register", "contractPayload": {} } }
{ "id": "ssc-b8923f70-c1f7-497f-961l", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "token", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBkYi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xldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAKICAgICAgICAgIC8vIGNoZWNrIGlmIHRoZSB0b2tlbiBhbHJlYWR5IGV4aXN0cwogICAgICAgICAgbGV0IHRva2VuID0gdG9rZW5zLmZpbmRPbmUoeyBzeW1ib2wgfSk7CiAgICAKICAgICAgICAgIGlmIChhc3NlcnQodG9rZW4gPT09IG51bGwsICdzeW1ib2wgYWxyZWFkeSBleGlzdHMnKSkgewogICAgICAgICAgICBjb25zdCBuZXdUb2tlbiA9IHsKICAgICAgICAgICAgICAnaXNzdWVyJzogc2VuZGVyLAogICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICBwcmVjaXNpb24sCiAgICAgICAgICAgICAgbWF4U3VwcGx5LAogICAgICAgICAgICAgICdzdXBwbHknOiAwCiAgICAgICAgICAgIH07CiAgICAKICAgICAgICAgICAgdG9rZW5zLmluc2VydChuZXdUb2tlbik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMuaXNzdWUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5LCBpc1NpZ25lZFdpdGhBY3RpdmVLZXkgfSA9IHBheWxvYWQ7CiAgICAKICAgICAgaWYgKGFzc2VydChpc1NpZ25lZFdpdGhBY3RpdmVLZXkgPT09IHRydWUsICd5b3UgbXVzdCB1c2UgYSBjdXN0b21fanNvbiBzaWduZWQgd2l0aCB5b3VyIGFjdGl2ZSBrZXknKQogICAgICAgICYmIHRvICYmIHR5cGVvZiB0byA9PT0gJ3N0cmluZycKICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bWJvbCA9PT0gJ3N0cmluZycKICAgICAgICAmJiBxdWFudGl0eSAmJiB0eXBlb2YgcXVhbnRpdHkgPT09ICdudW1iZXInKSB7CiAgICAKICAgICAgICBsZXQgdG9rZW5zID0g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mJykpIHsKICAgICAgICAgIGxldCBhY2NvdW50ID0gZGIuZmluZE9uZUluVGFibGUoJ2FjY291bnQnLCAnYWNjb3VudHMnLCB7ICdpZCc6IHRvIH0pOwogICAgCiAgICAgICAgICAvLyB0aGUgYWNjb3VudCBtdXN0IGhhdmUgYmVlbiByZWdpc3RlcmVkIGJlZm9yZQogICAgICAgICAgaWYgKGFzc2VydChhY2NvdW50ICE9PSBudWxsLCAndG8gYWNjb3VudCBkb2VzIG5vdCBleGlzdCcpKSB7CiAgICAgICAgICAgIGxldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAgICAgICAgIGxldCB0b2tlbiA9IHRva2Vucy5maW5kT25lKHsgc3ltYm9sIH0pOwogICAgCiAgICAgICAgICAgIC8vIHRoZSBzeW1ib2wgbXVzdCBleGlzdAogICAgICAgICAgICAvLyB0aGVuIHdlIG5lZWQgdG8gY2hlY2sgdGhhdCB0aGUgcXVhbnRpdHkgaXMgY29ycmVjdAogICAgICAgICAgICBpZiAoYXNzZXJ0KHRva2VuICE9PSBudWxsLCAnc3ltYm9sIGRvZXMgbm90IGV4aXN0JykKICAgICAgICAgICAgICAmJiBhc3NlcnQoY291bnREZWNpbWFscyhxdWFudGl0eSkgPD0gdG9rZW4ucHJlY2lzaW9uLCAnc3ltYm9sIHByZWNpc2lvbiBtaXNtYXRjaCcpCiAgICAgICAgICAgICAgJiYgYXNzZXJ0KHF1YW50aXR5ID4gMCwgJ211c3QgdHJhbnNmZXIgcG9zaXRpdmUgcXVhbnRpdHknKSkgewogICAgCiAgICAgICAgICAgICAgaWYgKHN1YkJhbGFuY2Uoc2VuZGVyLCB0b2tlbiwgcXVhbnRpdHkpKSB7CiAgICAgICAgICAgICAgICBhZGRCYWxhbmNlKHRvLCB0b2tlbiwgcXVhbnRpdHkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogICAgCiAgICBs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BudWxsKSB7CiAgICAgICAgYmFsYW5jZSA9IHsKICAgICAgICAgIGFjY291bnQsCiAgICAgICAgICAnc3ltYm9sJzogdG9rZW4uc3ltYm9sLAogICAgICAgICAgJ2JhbGFuY2UnOiBxdWFudGl0eQogICAgICAgIH0KICAgICAgICAKICAgICAgICBiYWxhbmNlcy5pbnNlcnQoYmFsYW5jZSk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgYmFsYW5jZS5iYWxhbmNlID0gY2FsY3VsYXRlQmFsYW5jZShiYWxhbmNlLmJhbGFuY2UsIHF1YW50aXR5LCB0b2tlbi5wcmVjaXNpb24sIHRydWUpOwogICAgCiAgICAgICAgYmFsYW5jZXMudXBkYXRlKGJhbGFuY2UpOwogICAgICB9CiAgICB9CiAgICAKICAgIGxldCBjYWxjdWxhdGVCYWxhbmNlID0gZnVuY3Rpb24gKGJhbGFuY2UsIHF1YW50aXR5LCBwcmVjaXNpb24sIGFkZCkgewogICAgICBpZiAocHJlY2lzaW9uID09PSAwKSB7CiAgICAgICAgcmV0dXJuIGFkZCA/IGJhbGFuY2UgKyBxdWFudGl0eSA6IGJhbGFuY2UgLSBxdWFudGl0eQogICAgICB9CiAgICAgIAogICAgICByZXR1cm4gYWRkID8gY3VycmVuY3koYmFsYW5jZSwgeyBwcmVjaXNpb24gfSkuc3VidHJhY3QocXVhbnRpdHkpIDogY3VycmVuY3koYmFsYW5jZSwgeyBwcmVjaXNpb24gfSkuc3VidHJhY3QocXVhbnRpdHkpOwogICAgfQogICAgCiAgICBsZXQgY291bnREZWNpbWFscyA9IGZ1bmN0aW9uICh2YWx1ZSkgewogICAgICBpZiAoTWF0aC5mbG9vcih2YWx1ZSkgPT09IHZhbHVlKSByZXR1cm4gMDsKICAgICAgcmV0dXJuIHZhbHVlLnRvU3RyaW5nKCkuc3BsaXQoJy4nKVsxXS5sZW5ndGggfHwgMDsKICAgIH0=" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961l", "json": { "contractName": "token", "contractAction": "create", "contractPayload": { "symbol": "PKTC", "precision": 0, "maxSupply": 1000000 } } }
{ "id": "ssc-b8923f70-c1f7-497f-961j", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "account", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961j", "json": { "contractName": "account", "contractAction": "register", "contractPayload": {} } }
{ "id": "ssc-b8923f70-c1f7-497f-961j", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "token", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBkYi5jcmVhdGVUYWJsZSgndG9rZW5zJyk7CiAgICAgIGRiLmNyZWF0ZVRhYmxlKCdiYWxhbmNlcycpOwogICAgfQogICAgCiAgICBhY3Rpb25zLmNyZWF0ZSA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgICAgIGNvbnN0IHsgc3ltYm9sLCBwcmVjaXNpb24sIG1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gIGlmIChhc3NlcnQodG9rZW4gPT09IG51bGwsICdzeW1ib2wgYWxyZWFkeSBleGlzdHMnKSkgewogICAgICAgICAgICBjb25zdCBuZXdUb2tlbiA9IHsKICAgICAgICAgICAgICAnaXNzdWVyJzogc2VuZGVyLAogICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICBwcmVjaXNpb24sCiAgICAgICAgICAgICAgbWF4U3VwcGx5LAogICAgICAgICAgICAgICdzdXBwbHknOiAwCiAgICAgICAgICAgIH07CiAgICAKICAgICAgICAgICAgdG9rZW5zLmluc2VydChuZXdUb2tlbik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMuaXNzdWUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5LCBpc1NpZ25lZFdpdGhBY3RpdmVLZXkgfSA9IHBheWxvYWQ7CiAgICAKICAgICAgaWYgKGFzc2VydChpc1NpZ25lZFdpdGhBY3RpdmVLZXkgPT09IHRydWUsICd5b3UgbXVzdCB1c2UgYSBjdXN0b21fanNvbiBzaWduZWQgd2l0aCB5b3VyIGFjdGl2ZSBrZXknKQogICAgICAgICYmIHRvICYmIHR5cGVvZiB0byA9PT0gJ3N0cmluZycKICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bWJvbCA9PT0gJ3N0cmluZycKICAgICAgICAmJiBxdWFudGl0eSAmJiB0eXBlb2YgcXVhbnRpdHkgPT09ICdudW1iZXInKSB7CiAgICAKICAgICAgICBsZXQgdG9rZW5zID0gZGIuZ2V0VGFibGUoJ3Rva2VucycpOwogICAgICAgIGxldCB0b2tlbiA9IHRva2Vucy5maW5kT25lKHsgc3ltYm9sIH0pOwogICAgCiAgICAgICAgLy8gdGhlIHN5bWJvbCBtdXN0IGV4aXN0CiAgICAgICAgLy8gdGhlIHNlbmRlciBtdXN0IGJlIHRoZSBpc3N1ZXI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YW5jZSk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgYmFsYW5jZS5iYWxhbmNlID0gY2FsY3VsYXRlQmFsYW5jZShiYWxhbmNlLmJhbGFuY2UsIHF1YW50aXR5LCB0b2tlbi5wcmVjaXNpb24sIHRydWUpOwogICAgCiAgICAgICAgYmFsYW5jZXMudXBkYXRlKGJhbGFuY2UpOwogICAgICB9CiAgICB9CiAgICAKICAgIGxldCBjYWxjdWxhdGVCYWxhbmNlID0gZnVuY3Rpb24gKGJhbGFuY2UsIHF1YW50aXR5LCBwcmVjaXNpb24sIGFkZCkgewogICAgICBpZiAocHJlY2lzaW9uID09PSAwKSB7CiAgICAgICAgcmV0dXJuIGFkZCA/IGJhbGFuY2UgKyBxdWFudGl0eSA6IGJhbGFuY2UgLSBxdWFudGl0eQogICAgICB9CgogICAgICByZXR1cm4gYWRkID8gY3VycmVuY3koYmFsYW5jZSwgeyBwcmVjaXNpb24gfSkuYWRkKHF1YW50aXR5KSA6IGN1cnJlbmN5KGJhbGFuY2UsIHsgcHJlY2lzaW9uIH0pLnN1YnRyYWN0KHF1YW50aXR5KTsKICAgIH0KICAgIAogICAgbGV0IGNvdW50RGVjaW1hbHMgPSBmdW5jdGlvbiAodmFsdWUpIHsKICAgICAgaWYgKE1hdGguZmxvb3IodmFsdWUpID09PSB2YWx1ZSkgcmV0dXJuIDA7CiAgICAgIHJldHVybiB2YWx1ZS50b1N0cmluZygpLnNwbGl0KCcuJylbMV0ubGVuZ3RoIHx8IDA7CiAgICB9" } } }
{ "id": "ssc-b8923f70-c1f7-497f-961j", "json": { "contractName": "token", "contractAction": "create", "contractPayload": { "symbol": "PKTC", "precision": 0, "maxSupply": 1000000 } } }
{ "id": "ssc-b8923f70-c1f7-497f-961j", "json": { "contractName": "token", "contractAction": "create", "contractPayload": { "symbol": "SMMT", "precision": 0, "maxSupply": 1000000 } } }
{ "id": "ssc-b8923f70-c1f7-497f-961j", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": {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wp9" } } }
{ "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": "Y29uc3QgVE9LRU5TWU1CT0wgPSAnU01NS1QnOwphY3Rpb25zLmNyZWF0ZVNTQyA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgZGIuY3JlYXRlVGFibGUoJ2JhbGFuY2VzJyk7CiAgbGV0IHJld2FyZHMgPSBkYi5jcmVhdGVUYWJsZSgncmV3YXJkcycpOwogIHJld2FyZHMuaW5zZXJ0KHsKICAgICdwZW5kaW5nUmV3YXJkcyc6IDAsCiAgICAncmV3YXJkc0Rpc3RyaWJ1dGlvbkludGVydmFsJzogMzAwMDAsCiAgICAnbGFzdEJsb2NrUmV3YXJkJzogcmVmU3RlZW1CbG9ja051bWJlciwKICAgICd0b2tlbklzc3VhbmNlUmF0ZSc6IDEsCiAgICAnbmV4dEhhbHZpbmcnOiA1MDAwMDAsCiAgICAnYmVuZWZpY2lhcmllcyc6IFsnc21tYXJrZXR0b2tlbiddCiAgfSkKfQoKYWN0aW9ucy51cGRhdGVSZXdhcmRzRGlzdHJpYnV0aW9uSW50ZXJ2YWwgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGlmIChzZW5kZXIgIT09IG93bmVyKSByZXR1cm47CgogIGNvbnN0IHsgbmJCbG9ja3MgfSA9IHBheWxvYWQ7CgogIGlmIChOdW1iZXIuaXNJbnRlZ2VyKG5iQmxvY2tzKSkgewogICAgbGV0IHJld2FyZHMgPSBkYi5nZXRUYWJsZSgncmV3YXJkcycpOwogICAgbGV0IHJlYyA9IHJld2FyZHMuZmluZE9uZSh7fSk7CiAgICByZWMucmV3YXJkc0Rpc3RyaWJ1dGlvbkludGVydmFsID0gbmJCbG9ja3M7CiAgICByZXdhcmR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uc3VidHJhY3QoYik7Cn0KCmxldCBjb3VudERlY2ltYWxzID0gZnVuY3Rpb24gKHZhbHVlKSB7CiAgaWYgKE1hdGguZmxvb3IodmFsdWUpID09PSB2YWx1ZSkgcmV0dXJuIDA7CiAgcmV0dXJuIHZhbHVlLnRvU3RyaW5nKCkuc3BsaXQoJy4nKVsxXS5sZW5ndGggfHwgMDsKfQ==" } } }
{ "id": "ssc-00000000000000000002", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "tokens", "params": "", "code": "Ly9jb25zdCBhY3Rpb25zID0ge30KLy9jb25zdCBhcGkgPSB7fQoKYWN0aW9ucy5jcmVhdGVTU0MgPSBhc3luYyAocGF5bG9hZCkgPT4gewogIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgndG9rZW5zJywgWydzeW1ib2wnXSk7CiAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCdiYWxhbmNlcycsIFsnYWNjb3VudCddKTsKICBhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoJ2NvbnRyYWN0c0JhbGFuY2VzJywgWydhY2NvdW50J10pOwogIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgncGFyYW1zJyk7CiAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCdwZW5kaW5nVW5zdGFrZXMnLCBbJ2FjY291bnQnLCAndW5zdGFrZUNvbXBsZXRlVGltZXN0YW1wJ10pOwoKICBjb25zdCBwYXJhbXMgPSB7fTsKICBwYXJhbXMudG9rZW5DcmVhdGlvbkZlZSA9ICcwJzsKICBhd2FpdCBhcGkuZGIuaW5zZXJ0KCdwYXJhbXMnLCBwYXJhbXMpOwp9OwoKYWN0aW9ucy51cGRhdGVQYXJhbXMgPSBhc3luYyAocGF5bG9hZCkgPT4gewogIGlmIChhcGkuc2VuZGVyICE9PSBhcGkub3duZXIpIHJldHVybjsKCiAgY29uc3QgeyB0b2tlbkNyZWF0aW9uRmVlIH0gPSBwYXlsb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IHF1YW50aXR5LCAnYmFsYW5jZXMnKTsKCiAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoZmluYWxUbyA9PT0gJ251bGwnKSB7CiAgICAgICAgICAgICAgdG9rZW4uY2lyY3VsYXRpbmdTdXBwbHkgPSBjYWxjdWxhdGVCYWxhbmNlVlR3bygKICAgICAgICAgICAgICAgIHRva2VuLmNpcmN1bGF0aW5nU3VwcGx5LCBxdWFudGl0eSwgdG9rZW4ucHJlY2lzaW9uLCBmYWxzZSwKICAgICAgICAgICAgICApOwogICAgICAgICAgICAgIGF3YWl0IGFwaS5kYi51cGRhdGUoJ3Rva2VucycsIHRva2VuKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgYXBpLmVtaXQoJ3RyYW5zZmVyJywgewogICAgICAgICAgICAgIGZyb206IGFwaS5zZW5kZXIsIHRvOiBmaW5hbFRvLCBzeW1ib2wsIHF1YW50aXR5LAogICAgICAgICAgICB9KTsKCiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KCiAgcmV0dXJuIGZhbHNlOwp9OwoKYWN0aW9ucy50cmFuc2ZlciA9IGFzeW5jIChwYXlsb2FkKSA9PiB7CiAgaWYgKGFwaS5yZWZTdGVlbUJsb2NrTnVtYmVyIDwgMzA4OTY1MDApIHsKICAgIGF3YWl0IHRyYW5zZmVyVk9uZShwYXlsb2FkKTsKICB9IGVsc2UgewogICAgYXdhaXQgdHJhbnNmZXJWVHdvKHBheWxvYWQpOwogIH0KfTsKCmFjdGlvbnMudHJhbnNmZXJUb0NvbnRyYWN0ID0gYXN5bmMgKHBheWxvYWQpID0+IHsKICBjb25zdCB7CiAgICB0bywgc3ltYm9sLCBxdWFudGl0eSwgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogIH0gPSBwYXlsb2FkOwoKICBpZiAoYXBpLmFzc2VydChpc1NpZ25lZF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pdHkpIDw9IHRva2VuLnByZWNpc2lvbiwgJ3N5bWJvbCBwcmVjaXNpb24gbWlzbWF0Y2gnKQogICAgICAgICAgJiYgYXBpLmFzc2VydChhcGkuQmlnTnVtYmVyKHF1YW50aXR5KS5ndCgwKSwgJ211c3QgdHJhbnNmZXIgcG9zaXRpdmUgcXVhbnRpdHknKSkgewogICAgICAgICAgaWYgKGF3YWl0IHN1YkJhbGFuY2VWVHdvKGFwaS5zZW5kZXIsIHRva2VuLCBxdWFudGl0eSwgJ2JhbGFuY2VzJykpIHsKICAgICAgICAgICAgY29uc3QgcmVzID0gYXdhaXQgYWRkQmFsYW5jZVZUd28oZmluYWxUbywgdG9rZW4sIHF1YW50aXR5LCAnY29udHJhY3RzQmFsYW5jZXMnKTsKCiAgICAgICAgICAgIGlmIChyZXMgPT09IGZhbHNlKSB7CiAgICAgICAgICAgICAgYXdhaXQgYWRkQmFsYW5jZVZUd28oYXBpLnNlbmRlciwgdG9rZW4sIHF1YW50aXR5LCAnYmFsYW5jZXMnKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoZmluYWxUbyA9PT0gJ251bGwnKSB7CiAgICAgICAgICAgICAgICB0b2tlbi5jaXJjdWxhdGluZ1N1cHBseSA9IGNhbGN1bGF0ZUJhbGFuY2VWVHdvKAogICAgICAgICAgICAgICAgICB0b2tlbi5jaXJjdWxhdGluZ1N1cHBseSwgcXVhbnRpdHksIHRva2VuLnByZWNpc2lvbiwgZmFsc2UsCiAgICAgICAgICAgICAgICApOwogICAgICAgICAgICAgICAgYXdhaXQgYXBpLmRiLnVwZGF0ZSgndG9rZW5zJywgdG9rZW4pOwogICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgYXBpLmVtaXQoJ3RyYW5zZmVyVG9Db250cmFjdCcsIHsKICAgICAgICAgICAgICAgIGZyb206IGFwaS5zZW5kZXIsIHRvOiBmaW5hbFRvLCBzeW1ib2wsIHF1YW50aXR5LAogICAgICAgICAgICA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uZ3QoMCksICdtdXN0IHRyYW5zZmVyIHBvc2l0aXZlIHF1YW50aXR5JykpIHsKCiAgICAgICAgICAgIGlmIChhd2FpdCBzdWJCYWxhbmNlVlR3byhmcm9tLCB0b2tlbiwgcXVhbnRpdHksICdjb250cmFjdHNCYWxhbmNlcycpKSB7CiAgICAgICAgICAgICAgY29uc3QgcmVzID0gYXdhaXQgYWRkQmFsYW5jZVZUd28oZmluYWxUbywgdG9rZW4sIHF1YW50aXR5LCB0YWJsZSk7CgogICAgICAgICAgICAgIGlmIChyZXMgPT09IGZhbHNlKSB7CiAgICAgICAgICAgICAgICBhd2FpdCBhZGRCYWxhbmNlVlR3byhmcm9tLCB0b2tlbiwgcXVhbnRpdHksICdjb250cmFjdHNCYWxhbmNlcycpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBpZiAoZmluYWxUbyA9PT0gJ251bGwnKSB7CiAgICAgICAgICAgICAgICAgIHRva2VuLmNpcmN1bGF0aW5nU3VwcGx5ID0gY2FsY3VsYXRlQmFsYW5jZVZUd28oCiAgICAgICAgICAgICAgICAgICAgdG9rZW4uY2lyY3VsYXRpbmdTdXBwbHksIHF1YW50aXR5LCB0b2tlbi5wcmVjaXNpb24sIGZhbHNlLAogICAgICAgICAgICAgICAgICApOwogICAgICAgICAgICAgICAgICBhd2FpdCBhcGkuZGIudXBkYXRlKCd0b2tlbnMnLCB0b2tlbik7CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgYXBpLmVtaXQoJ3RyYW5zZmVyRnJvbUNvbnRyYWN0JywgewogICAgICAgICAgICAgICAgICBmcm9tLCB0bzogZmluYWxUbywgc3ltYm9sLCBxdWFudGl0eSwKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KfTsKCmNvbnN0IHByb2Nlc3NVbnN0YWtlID0gYXN5bmMgKHVuc3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mRpdmlkZWRCeShuYkRheXMxMDBQZXJjZW50UmVnZW5lcmF0aW9uU2VjcykKICAgIC5tdWx0aXBsaWVkQnkoc2Vjb25kc2FnbykKICAgIC50b0ZpeGVkKDIpOwoKICBjb25zdCBuZXdWb3RpbmdQb3dlciA9IGFwaS5CaWdOdW1iZXIoYmFsYW5jZS52b3RpbmdQb3dlcikKICAgIC5wbHVzKHJlZ2VuZXJhdGVkUG93ZXIpCiAgICAudG9GaXhlZCgyKTsKCiAgcmV0dXJuIGFwaS5CaWdOdW1iZXIobmV3Vm90aW5nUG93ZXIpLmd0KDEwMCkgPyAnMTAwLjAwJyA6IG5ld1ZvdGluZ1Bvd2VyOwp9OwoKY29uc3QgY291bnREZWNpbWFscyA9IHZhbHVlID0+IGFwaS5CaWdOdW1iZXIodmFsdWUpLmRwKCk7Cg==" } } }
{ "id": "ssc-00000000000000000002", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "test", "params": "", "code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBhc3luYyAocGF5bG9hZCkgPT4gewogICAgICAgICAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCd0ZXN0VXBkYXRlVGFibGUnKTsKICAgICAgICB9" } } }
{ "id": "ssc-testnet1", "json": { "contractName": "contract", "contractAction": "update", "contractPayload": { "name": "tokens", "params": "", "code": "YWN0aW9ucy5jcmVhdGVTU0M9KGFzeW5jKCk9PntsZXQgYT1hd2FpdCBhcGkuZGIudGFibGVFeGlzdHMoInRva2VucyIpO2lmKCExPT09YSl7YXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCJ0b2tlbnMiLFsic3ltYm9sIl0pLGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgiYmFsYW5jZXMiLFsiYWNjb3VudCJdKSxhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoImNvbnRyYWN0c0JhbGFuY2VzIixbImFjY291bnQiXSksYXdhaXQgYXBpLmRiLmNyZWF0ZVR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ZVthXTthd2FpdCBwcm9jZXNzVW5kZWxlZ2F0aW9uKHQpfXQ9KGU9YXdhaXQgYXBpLmRiLmZpbmQoInBlbmRpbmdVbmRlbGVnYXRpb25zIix7Y29tcGxldGVUaW1lc3RhbXA6eyRsdGU6YX19KSkubGVuZ3RofX19KTs=" } } }
{ "id": "ssc-testnet1", "json": { "contractName": "contract", "contractAction": "update", "contractPayload": { "name": "witnesses", "params": "", "code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBnbG9iYWwgYWN0aW9ucywgYXBpICovCgpjb25zdCBOQl9BUFBST1ZBTFNfQUxMT1dFRCA9IDMwOwpjb25zdCBOQl9UT1BfV0lUTkVTU0VTID0gNDsKY29uc3QgTkJfQkFDS1VQX1dJVE5FU1NFUyA9IDE7CmNvbnN0IE5CX1dJVE5FU1NFUyA9IE5CX1RPUF9XSVRORVNTRVMgKyBOQl9CQUNLVVBfV0lUTkVTU0VTOwpjb25zdCBOQl9XSVRORVNTRVNfU0lHTkFUVVJFU19SRVFVSVJFRCA9IDM7CmNvbnN0IE1BWF9ST1VORFNfTUlTU0VEX0lOX0FfUk9XID0gMzsgLy8gYWZ0ZXIgdGhhdCB0aGUgd2l0bmVzcyBpcyBkaXNhYmxlZApjb25zdCBNQVhfUk9VTkRfUFJPUE9TSVRJT05fV0FJVElOR19QRVJJT0QgPSA0MDsgLy8gMjAgYmxvY2tzCmNvbnN0IE5CX1RPS0VOU19UT19SRVdBUkQgPSAnMC4wMTkwMjU4Nyc7CmNvbnN0IE5CX1RPS0VOU19ORUVERURfQkVGT1JFX1JFV0FSRElORyA9ICcwLjA5NTEyOTM1JzsKLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIG5vLXRlbXBsYXRlLWN1cmx5LWluLXN0cmluZwpjb25zdCBVVElMSVRZX1RPS0VOX1NZTUJPTCA9ICJTU0MiOwovLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgbm8tdGVt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Agd2l0bmVzcy5JUCA9IElQOwogICAgICAgICAgd2l0bmVzcy5SUENQb3J0ID0gUlBDUG9ydDsKICAgICAgICAgIHdpdG5lc3MuUDJQUG9ydCA9IFAyUFBvcnQ7CiAgICAgICAgICB3aXRuZXNzLnNpZ25pbmdLZXkgPSBzaWduaW5nS2V5OwogICAgICAgICAgd2l0bmVzcy5lbmFibGVkID0gZW5hYmxlZDsKICAgICAgICAgIGF3YWl0IGFwaS5kYi51cGRhdGUoJ3dpdG5lc3NlcycsIHdpdG5lc3MpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3aXRuZXNzID0gewogICAgICAgICAgICBhY2NvdW50OiBhcGkuc2VuZGVyLAogICAgICAgICAgICBhcHByb3ZhbFdlaWdodDogeyAkbnVtYmVyRGVjaW1hbDogJzAnIH0sCiAgICAgICAgICAgIHNpZ25pbmdLZXksCiAgICAgICAgICAgIElQLAogICAgICAgICAgICBSUENQb3J0LAogICAgICAgICAgICBQMlBQb3J0LAogICAgICAgICAgICBlbmFibGVkLAogICAgICAgICAgICBtaXNzZWRSb3VuZHM6IDAsCiAgICAgICAgICAgIG1pc3NlZFJvdW5kc0luQVJvdzogMCwKICAgICAgICAgICAgdmVyaWZpZWRSb3VuZHM6IDAsCiAgICAgICAgICAgIGxhc3RSb3VuZFZlcmlmaWVkOiBudWxsLAogICAgICAgICAgICBsYXN0QmxvY2tWZXJpZmllZDogbnVsbCwKICAgICAgICAgIH07CiAgICAgICAgICBhd2FpdCBhcGkuZGIuaW5zZXJ0KCd3aXRuZXNzZXMnLCB3aXRuZXNzKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICB9Cn07CgphY3Rpb25zLmFwcHJvdmUgPSBhc3luYyAocGF5bG9hZCkgPT4gewogIGNvbnN0IHsgd2l0bmVzcyB9ID0gcGF5bG9hZDsKCiAgaWYgKGFwaS5hc3NlcnQod2l0bmVzcyAmJiB0eXBlb2Ygd2l0bmVzcyA9PT0gJ3N0cmluZycgJiYgd2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uZ2U6CiAgICAgICAgICAgIGZyb20gMyw0MDAuMDAwMDAwMSB0byAxMCwwMDAKICAgICAgKi8KCiAgICAgIC8vIGdldCBhIGRldGVybWluaXN0aWMgcmFuZG9tIHdlaWdodAogICAgICBjb25zdCByYW5kb20gPSBhcGkucmFuZG9tKCk7CiAgICAgIGxldCByYW5kb21XZWlnaHQgPSBudWxsOwoKICAgICAgbGV0IG9mZnNldCA9IDA7CiAgICAgIGxldCBhY2NXZWlnaHQgPSAwOwoKICAgICAgbGV0IHdpdG5lc3NlcyA9IGF3YWl0IGFwaS5kYi5maW5kKAogICAgICAgICd3aXRuZXNzZXMnLAogICAgICAgIHsKICAgICAgICAgIGFwcHJvdmFsV2VpZ2h0OiB7CiAgICAgICAgICAgICRndDogewogICAgICAgICAgICAgICRudW1iZXJEZWNpbWFsOiAnMCcsCiAgICAgICAgICAgIH0sCiAgICAgICAgICB9LAogICAgICAgIH0sCiAgICAgICAgMTAwLCAvLyBsaW1pdAogICAgICAgIG9mZnNldCwgLy8gb2Zmc2V0CiAgICAgICAgWwogICAgICAgICAgeyBpbmRleDogJ2FwcHJvdmFsV2VpZ2h0JywgZGVzY2VuZGluZzogdHJ1ZSB9LAogICAgICAgIF0sCiAgICAgICk7CgogICAgICBkbyB7CiAgICAgICAgZm9yIChsZXQgaW5kZXggPSAwOyBpbmRleCA8IHdpdG5lc3Nlcy5sZW5ndGg7IGluZGV4ICs9IDEpIHsKICAgICAgICAgIGNvbnN0IHdpdG5lc3MgPSB3aXRuZXNzZXNbaW5kZXhdOwoKICAgICAgICAgIC8vIGNhbGN1bGF0ZSBhIHJhbmRvbSB3ZWlnaHQgaWYgbm90IGRvbmUgeWV0CiAgICAgICAgICBpZiAoc2NoZWR1bGUubGVuZ3RoID49IE5CX1RPUF9XSVRORVNTRVMKICAgICAgICAgICAgJiYgcmFuZG9tV2VpZ2h0ID09PSBudWxsKSB7CiAgICAgICAgICAgIGNvbnN0IG1pbiA9IGFwaS5CaWdOdW1iZXIoYWNjV2VpZ2h0KQogICAgICAgICAgICAgIC5wbHVzKFVUSUxJVFlfVE9LRU5fTUlOX1ZBTFVFKTsKCiAgICAgICAgICAgIHJhbmRvbVdlaWdodCA9IGFwaS5CaWdOdW1iZXIodG90YWxBcHByb3ZhbFdlaWdodCkKICAgICAgICAgICAgICAubWludXMobWluKQogICAgICAgICAgICAgIC50aW1lcyhyYW5kb20pCiAgICAgICAgICAgICAgLnBsdXMobWluKQogICAgICAgICAgICAgIC50b0ZpeGVkKFVUSUxJVFlfVE9LRU5fUFJFQ0lTSU9OKTsKICAgICAgICAgIH0KCiAgICAgICAgICBhY2NXZWlnaHQgPSBhcGkuQmlnTnVtYmVyKGFjY1dlaWdodCkKICAgICAgICAgICAgLnBsdXMod2l0bmVzcy5hcHByb3ZhbFdlaWdodC4kbnVtYmVyRGVjaW1hbCkKICAgICAgICAgICAgLnRvRml4ZWQoVVRJTElUWV9UT0tFTl9QUkVDSVNJT04pOwoKICAgICAgICAgIC8vIGlmIHRoZSB3aXRuZXNzIGlzIGVuYWJsZWQKICAgICAgICAgIGlmICh3aXRuZXNzLmVuYWJsZWQgPT09IHRydWUpIHsKICAgICAgICAgICAgLy8gaWYgd2UgaGF2ZW4ndCBmb3VuZCBhbGwgdGhlIHRvcCB3aXRuZXNzZXMgeWV0CiAgICAgICAgICAgIGlmIChzY2hlZHVsZS5sZW5ndGggPCBOQl9UT1BfV0lUTkVTU0VTCiAgICAgICAgICAgICAgfHwgYXBpLkJpZ051bWJlcihyYW5kb21XZWlnaHQpLmx0ZShhY2NXZWlnaHQpKSB7CiAgICAgICAgICAgICAgc2NoZWR1bGUucHVzaCh7CiAgICAgICAgICAgICAgICB3aXRuZXNzOiB3aXRuZXNzLmFjY291bnQsCiAgICAgICAgICAgICAgICBibG9ja051bWJlcjogbnVsbCwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQoKICAgICAgICAgIGlmIChzY2hlZHVsZS5sZW5ndGggPj0gTkJfV0lUTkVTU0VTKSB7CiAgICAgICAgICAgIGluZGV4ID0gd2l0bmVzc2VzLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGlmIChzY2hlZHVsZS5sZW5ndGggPCBOQl9XSVRORVNTRVMpIHsKICAgICAgICAgIG9mZnNldCArPSAxMDA7CiAgICAgICAgICB3aXRuZXNzZXMgPSBhd2FpdCBhcGkuZGIuZmluZCgKICAgICAgICAgICAgJ3dpdG5lc3NlcycsCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICBhcHByb3ZhbFdlaWdodDogewogICAgICAgICAgICAgICAgJGd0OiB7CiAgICAgICAgICAgICAgICAgICRudW1iZXJEZWNpbWFsOiAnMCcsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgIH0sCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIDEwMCwgLy8gbGltaXQKICAgICAgICAgICAgb2Zmc2V0LCAvLyBvZmZzZXQKICAgICAgICAgICAgWwogICAgICAgICAgICAgIHsgaW5kZXg6ICdhcHByb3ZhbFdlaWdodCcsIGRlc2NlbmRpbmc6IHRydWUgfSwKICAgICAgICAgICAgXSwKICAgICAgICAgICk7CiAgICAgICAgfQogICAgICB9IHdoaWxlICh3aXRuZXNzZXMubGVuZ3RoID4gMCAmJiBzY2hlZHVsZS5sZW5ndGggPCBOQl9XSVRORVNTRVMpOwogICAgfQoKICAgIC8vIGlmIHRoZXJlIGFyZSBlbm91Z2ggd2l0bmVzc2VzIHNjaGVkdWxlZAogICAgaWYgKHNjaGVkdWxlLmxlbmd0aCA9PT0gTkJfV0lUTkVTU0VTKSB7CiAgICAgIC8vIHNodWZmbGUgdGhlIHdpdG5lc3NlcwogICAgICBsZXQgajsgbGV0IHg7CiAgICAgIGZvciAobGV0IGkgPSBzY2hlZHVsZS5sZW5ndGggLSAxOyBpID4gMDsgaSAtPSAxKSB7CiAgICAgICAgY29uc3QgcmFuZG9tID0gYXBpLnJhbmRvbSgpOwogICAgIC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0pOwogICAgICAgICAgaWYgKHdpdG5lc3MgIT09IG51bGwpIHsKICAgICAgICAgICAgY29uc3Qgc2lnbmF0dXJlID0gc2lnbmF0dXJlcy5maW5kKHMgPT4gc1swXSA9PT0gd2l0bmVzcy5hY2NvdW50KTsKICAgICAgICAgICAgaWYgKHNpZ25hdHVyZSkgewogICAgICAgICAgICAgIGlmIChhcGkuY2hlY2tTaWduYXR1cmUoCiAgICAgICAgICAgICAgICBjYWxjdWxhdGVkUm91bmRIYXNoLCBzaWduYXR1cmVbMV0sIHdpdG5lc3Muc2lnbmluZ0tleSwgdHJ1ZSwKICAgICAgICAgICAgICApKSB7CiAgICAgICAgICAgICAgICBhcGkuZGVidWcoYHdpdG5lc3MgJHt3aXRuZXNzLmFjY291bnR9IHNpZ25lZCByb3VuZCAke3JvdW5kfWApOwogICAgICAgICAgICAgICAgc2lnbmF0dXJlc0NoZWNrZWQgKz0gMTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIC8vIHRoZSBjdXJyZW50IHdpdG5lc3Mgd2lsbCBzaG93IGFzIHRoZSB3aXRuZXNzIHRoYXQgdmVyaWZpZWQgdGhlIGJsb2NrcyBmcm9tIHRoZSByb3VuZAogICAgICAgICAgICB2ZXJpZmllZEJsb2NrSW5mb3JtYXRpb24ucHVzaCgKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBibG9ja051bWJlcjogc2NoZWR1bGVkV2l0bmVzcy5ibG9ja051bWJlciwKICAgICAgICAgICAgICAgIHdpdG5lc3M6IGN1cnJlbnRXaXRuZXNzLAogICAgICAgICAgICAgICAgc2lnbmluZ0tleTogY3VycmVudFdpdG5lc3NJbmZvLnNpZ25pbmdLZXksCiAgICAgICAgICAgICAgICByb3VuZFNpZ25hdHVyZTogY3VycmVudFdpdG5lc3NTaWduYXR1cmVbMV0sCiAgICAgICAgICAgICAgICByb3VuZCwKICAgICAgICAgICAgICAgIHJvdW5kSGFzaCwKICAgICAgICAgIC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lcmlmaWVkID0gbGFzdEJsb2NrUm91bmQ7CiAgICAgICAgICB3aXRuZXNzLnZlcmlmaWVkUm91bmRzICs9IDE7CiAgICAgICAgICBhd2FpdCBhcGkuZGIudXBkYXRlKCd3aXRuZXNzZXMnLCB3aXRuZXNzKTsKCiAgICAgICAgICAvLyBjYWxjdWxhdGUgbmV3IHNjaGVkdWxlCiAgICAgICAgICBhd2FpdCBtYW5hZ2VXaXRuZXNzZXNTY2hlZHVsZSgpOwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KfTsKCmFjdGlvbnMuc2NoZWR1bGVXaXRuZXNzZXMgPSBhc3luYyAoKSA9PiB7CiAgaWYgKGFwaS5zZW5kZXIgIT09ICdudWxsJykgcmV0dXJuOwoKICBhd2FpdCBtYW5hZ2VXaXRuZXNzZXNTY2hlZHVsZSgpOwp9Owo=" } } }
{ "id": "ssc-testnet1", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "inflation", "params": "", "code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBnbG9iYWwgYWN0aW9ucywgYXBpICovCgovLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgbm8tdGVtcGxhdGUtY3VybHktaW4tc3RyaW5nCmNvbnN0IFVUSUxJVFlfVE9LRU5fU1lNQk9MID0gIlNTQyI7CgphY3Rpb25zLmNyZWF0ZVNTQyA9IGFzeW5jICgpID0+IHsKCn07CgphY3Rpb25zLmlzc3VlTmV3VG9rZW5zID0gYXN5bmMgKCkgPT4gewogIGlmIChhcGkuc2VuZGVyICE9PSAnbnVsbCcpIHJldHVybjsKCiAgLy8gaXNzdWUgdG9rZW5zIHRvIHN0ZWVtc2MKICAvLyAxMDBrIHRva2VucyBwZXIgeWVhciA9IDExLjQxNTUyNTExIHRva2VucyBwZXIgaG91ciAoYW4gaG91ciA9IDEyMDAgYmxvY2tzKQogIGxldCBuYlRva2VucyA9ICcxMS40MTU1MjUxMSc7CiAgYXdhaXQgYXBpLmV4ZWN1dGVTbWFydENvbnRyYWN0KCd0b2tlbnMnLCAnaXNzdWUnLCB7IHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsIHF1YW50aXR5OiBuYlRva2VucywgdG86ICdzdGVlbXNjJyB9KTsKCiAgLy8gaXNzdWUgdG9rZW5zIHRvIGVuZ3Bvb2wKICAvLyAxMDBrIHRva2VucyBwZXIgeWVhciA9IDExLjQxNTUyNTExIHRva2VucyBwZXIgaG91ciAoYW4gaG91ciA9IDEyMDAgYmxvY2tzKQogIG5iVG9rZW5zID0gJzExLjQxNTUyNTExJzsKICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ3Rva2VucycsICdpc3N1ZScsIHsgc3ltYm9sOiBVVElMSVRZX1RPS0VOX1NZTUJPTCwgcXVhbnRpdHk6IG5iVG9rZW5zLCB0bzogJ2VuZ3Bvb2wnIH0pOwoKICAvLyBpc3N1ZSB0b2tlbnMgdG8gIndpdG5lc3NlcyIgY29udHJhY3QKICAvLyAyMDBrIHRva2VucyBwZXIgeWVhciA9IDIyLjgzMTA1MDIyIHRva2VucyBwZXIgaG91ciAoYW4gaG91ciA9IDEyMDAgYmxvY2tzKQogIG5iVG9rZW5zID0gJzIyLjgzMTA1MDIyJzsKICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ3Rva2VucycsICdpc3N1ZVRvQ29udHJhY3QnLCB7IHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsIHF1YW50aXR5OiBuYlRva2VucywgdG86ICd3aXRuZXNzZXMnIH0pOwp9Owo=" } } }
{ "id": "ssc-testnet1", "json": { "contractName": "contract", "contractAction": "update", "contractPayload": { "name": "nft", "params": "", "code": "Y29uc3QgQ09OVFJBQ1RfTkFNRT0ibmZ0IixVVElMSVRZX1RPS0VOX1NZTUJPTD0iU1NDIixNQVhfTlVNX0FVVEhPUklaRURfSVNTVUVSUz0xM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bmZvOml9KX19KTs=" } } }
{ "id": "ssc-testnet1", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "crittermanager", "params": "", "code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBlc2xpbnQtZGlzYWJsZSBtYXgtbGVuICovCi8qIGdsb2JhbCBhY3Rpb25zLCBhcGkgKi8KCi8vIHRlc3QgY29udHJhY3QgdG8gZGVtb25zdHJhdGUgU3BsaW50ZXJsYW5kcyBzdHlsZQovLyBwYWNrIGlzc3VhbmNlIG9mIGNvbGxlY3RhYmxlIGNyaXR0ZXJzCmNvbnN0IENPTlRSQUNUX05BTUUgPSAnY3JpdHRlcm1hbmFnZXInOwoKLy8gbm9ybWFsbHkgd2Ugd291bGQgdXNlIGFwaS5vd25lciB0byByZWZlciB0byB0aGUgY29udHJhY3QKLy8gb3duZXIgKHRoZSBhY2NvdW50IHRoYXQgZGVwbG95ZWQgdGhlIGNvbnRyYWN0KSwgYnV0IGZvciBub3cKLy8gY29udHJhY3QgZGVwbG95bWVudCBpcyByZXN0cmljdGVkLCBzbyB3ZSBuZWVkIGFub3RoZXIgd2F5Ci8vIHRvIHJlY29nbml6ZSB0aGUgQ3JpdHRlciBhcHAgb3duZXIKY29uc3QgQ1JJVFRFUl9DUkVBVE9SID0gJ2NyeXB0b21hbmNlcic7CgovLyB0aGlzIHBsYWNlaG9sZGVyIHJlcHJlc2VudHMgRU5HIHRva2VucyBvbiB0aGUgbWFpbm5ldCBhbmQgU1NDIG9uIHRoZSB0ZXN0bmV0Ci8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBuby10ZW1wbGF0ZS1jdXJseS1pbi1zdHJpbmcKY29uc3QgVVRJTElUWV9UT0tFTl9TWU1CT0wgPSAiU1NDIjsKCi8vIHdlIHdpbGwgaXNzdWUgY3JpdHRlcnMgaW4gInBhY2tzIiBvZiA1IGF0IGEgdGltZQpjb25zdCBDUklUVEVSU19QRVJfUEFDSyA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c2VuZGVyLCAnbnVsbCcsIHBhY2tTeW1ib2wsIHBhY2tzLnRvU3RyaW5nKCksICd0cmFuc2ZlcicpLCAndW5hYmxlIHRvIHRyYW5zZmVyIHBhY2sgdG9rZW5zJykpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CgogICAgICAgIC8vIHdlIHdpbGwgaXNzdWUgY3JpdHRlcnMgaW4gcGFja3Mgb2YgNSBhdCBvbmNlCiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBwYWNrczsgaSArPSAxKSB7CiAgICAgICAgICBjb25zdCBpbnN0YW5jZXMgPSBbXTsKICAgICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgQ1JJVFRFUlNfUEVSX1BBQ0s7IGogKz0gMSkgewogICAgICAgICAgICBpbnN0YW5jZXMucHVzaChnZW5lcmF0ZVJhbmRvbUNyaXR0ZXIoZWRpdGlvbk1hcHBpbmdbcGFja1N5bWJvbF0sIGFwaS5zZW5kZXIpKTsKICAgICAgICAgIH0KCiAgICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICdpc3N1ZU11bHRpcGxlJywgewogICAgICAgICAgICBpbnN0YW5jZXMsCiAgICAgICAgICAgIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfQogICAgfQogIH0KICByZXR1cm4gZmFsc2U7Cn07Cg==" } } }
{ "id": "ssc-testnet1", "json": { "contractName": "contract", "contractAction": "deploy", "contractPayload": { "name": "nftmarket", "params": "", "code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBlc2xpbnQtZGlzYWJsZSBtYXgtbGVuICovCi8qIGVzbGludC1kaXNhYmxlIHByZWZlci10ZW1wbGF0ZSAqLwovKiBlc2xpbnQtZGlzYWJsZSBuby11bmRlcnNjb3JlLWRh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vLyB0cmFuc2ZlciByZXN1bHRzIGFuZCBvbmx5IGNhbmNlbCBvcmRlcnMgZm9yIHRoZSB0cmFuc2ZlcnMgdGhhdCBzdWNjZWVkZWQKICAgICAgaWYgKHJlcy5ldmVudHMpIHsKICAgICAgICBjb25zdCBncm91cGluZ01hcCA9IHt9OwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgcmVzLmV2ZW50cy5sZW5ndGg7IGogKz0gMSkgewogICAgICAgICAgY29uc3QgZXYgPSByZXMuZXZlbnRzW2pdOwogICAgICAgICAgaWYgKGV2LmNvbnRyYWN0ICYmIGV2LmV2ZW50ICYmIGV2LmRhdGEKICAgICAgICAgICAgJiYgZXYuY29udHJhY3QgPT09ICduZnQnCiAgICAgICAgICAgICYmIGV2LmV2ZW50ID09PSAndHJhbnNmZXInCiAgICAgICAgICAgICYmIGV2LmRhdGEuZnJvbSA9PT0gQ09OVFJBQ1RfTkFNRQogICAgICAgICAgICAmJiBldi5kYXRhLmZyb21UeXBlID09PSAnYycKICAgICAgICAgICAgJiYgZXYuZGF0YS50byA9PT0gYXBpLnNlbmRlcgogICAgICAgICAgICAmJiBldi5kYXRhLnRvVHlwZSA9PT0gJ3UnCiAgICAgICAgICAgICYmIGV2LmRhdGEuc3ltYm9sID09PSBzeW1ib2wpIHsKICAgICAgICAgICAgLy8gdHJhbnNmZXIgaXMgdmVyaWZpZWQsIG5vdyB3ZSBjYW4gY2FuY2VsIHRoZSBvcmRlcgogICAgICAgICAgICBjb25zdCBpbnN0YW5jZUlkID0gZXYuZGF0YS5pZDsKICAgICAgICAgICAgaWYgKGluc3RhbmNlSWQgaW4gaWRNYXApIHsKICAgICAgICAgICAgICBjb25zdCBvcmRlciA9IGlkTWFwW2luc3RhbmNlSWRdOwoKICAgICAgICAgICAgICBhd2FpdCBhcGkuZGIucmVtb3ZlKG1hcmtldFRhYmxlTmFtZSwgb3JkZXIpOwoKICAgICAgICAgICAgICBhcGkuZW1pdCgnY2FuY2VsT3JkZXInLCB7CiAgICAgICAgICAgICAgICBhY2NvdW50OiBvcmRlci5hY2NvdW50LAogICAgICAgICAgICAgICAgb3duZWRCeTogb3JkZXIub3duZWRCeSwKICAgICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICAgIG5mdElkOiBvcmRlci5uZnRJZCwKICAgICAgICAgICAgICAgIHRpbWVzdGFtcDogb3JkZXIudGltZXN0YW1wLAogICAgICAgICAgICAgICAgcHJpY2U6IG9yZGVyLnByaWNlLAogICAgICAgICAgICAgICAgcHJpY2VTeW1ib2w6IG9yZGVyLnByaWNlU3ltYm9sLAogICAgICAgICAgICAgICAgZmVlOiBvcmRlci5mZWUsCiAgICAgICAgICAgICAgICBvcmRlcklkOiBvcmRlci5faWQsCiAgICAgICAgICAgICAgfSk7CgogICAgICAgICAgICAgIGNvbnN0IGtleSA9IG1ha2VHcm91cGluZ0tleShvcmRlci5ncm91cGluZywgbmZ0Lmdyb3VwQnkpOwogICAgICAgICAgICAgIGNvbnN0IGdyb3VwSW5mbyA9IGtleSBpbiBncm91cGluZ01hcAogICAgICAgICAgICAgICAgPyBncm91cGluZ01hcFtrZXldCiAgICAgICAgICAgICAgICA6IHsKICAgICAgICAgICAgICAgICAgZ3JvdXBpbmc6IG9yZGVyLmdyb3VwaW5nLAogICAgICAgICAgICAgICAgICBpc0luQ29sbGVjdGlvbjogZmFsc2UsCiAgICAgICAgICAgICAgICAgIGNvdW50OiAwLAogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICBncm91cEluZm8uY291bnQgLT0gMTsKICAgICAgICAgICAgICBncm91cGluZ01hcFtrZXldID0gZ3JvdXBJbmZvOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyB1cGRhdGUgb3BlbiBpbnRlcmVzdCBtZXRyaWNzCiAgICAgICAgYXdhaXQgdXBkYXRlT3BlbkludGVyZXN0KCdzZWxsJywgc3ltYm9sLCBwcmljZVN5bWJvbCwgZ3JvdXBpb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ID0gYXdhaXQgYXBpLmRiLmZpbmRPbmVJblRhYmxlKCduZnQnLCAnbmZ0cycsIHsgc3ltYm9sIH0pOwogICAgICBpZiAoIWFwaS5hc3NlcnQobmZ0ICYmIG5mdC5ncm91cEJ5ICYmIG5mdC5ncm91cEJ5Lmxlbmd0aCA+IDAsICdtYXJrZXQgZ3JvdXBpbmcgbm90IHNldCcpKSB7CiAgICAgICAgcmV0dXJuOwogICAgICB9CgogICAgICAvLyBsb29rIHVwIG9yZGVyIGluZm8KICAgICAgY29uc3Qgb3JkZXJzID0gYXdhaXQgYXBpLmRiLmZpbmQoCiAgICAgICAgbWFya2V0VGFibGVOYW1lLAogICAgICAgIHsKICAgICAgICAgIG5mdElkOiB7CiAgICAgICAgICAgICRpbjogbmZ0cywKICAgICAgICAgIH0sCiAgICAgICAgfSwKICAgICAgICBNQVhfTlVNX1VOSVRTX09QRVJBQkxFLAogICAgICAgIDAsCiAgICAgICAgW3sgaW5kZXg6ICduZnRJZCcsIGRlc2NlbmRpbmc6IGZhbHNlIH1dLAogICAgICApOwoKICAgICAgaWYgKG9yZGVycy5sZW5ndGggPiAwKSB7CiAgICAgICAgLy8gZG8gYSBjb3VwbGUgbW9yZSBzYW5pdHkgY2hlY2tzCiAgICAgICAgbGV0IHByaWNlU3ltYm9sID0gJyc7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBvcmRlcnMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICAgIGNvbnN0IG9yZGVyID0gb3JkZXJzW2ldOwogICAgICAgICAgaWYgKHByaWNlU3ltYm9sID09PSAnJykgewogICAgICAgICAgICAoeyBwcmljZVN5bWJvbCB9ID0gb3JkZXIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKCFhcGkuYXNzZXJ0KCEob3JkZXIub3duZWRCeSA9PT0gJ3UnICYmIG9yZGVyLmFjY291bnQgPT09IGFwaS5zZW5kZXIpLCAnY2Fubm90IGZpbGwgeW91ciBvd24gb3JkZXJzJykKICAgICAgICAgICAgfHwgIWFwaS5hc3NlcnQocHJpY2VTeW1ib2wgPT09IG9yZGVyLnByaWNlU3ltYm9sLCAnYWxsIG9yZGVycyBtdXN0IGhhdmUgdGhlIHNhbWUgcHJpY2Ugc3ltYm9sJykpIHsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvLyBnZXQgdGhlIHByaWNlIHRva2VuIHBhcmFtcwogICAgICAgIGNvbnN0IHRva2VuID0gYXdhaXQgYXBpLmRiLmZpbmRPbmVJblRhYmxlKCd0b2tlbnMnLCAndG9rZW5zJywgeyBzeW1ib2w6IHByaWNlU3ltYm9sIH0pOwogICAgICAgIGlmICghdG9rZW4pIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIC8vIGNyZWF0ZSBvcmRlciBtYXBzCiAgICAgICAgbGV0IGZlZVRvdGFsID0gYXBpLkJpZ051bWJlcigwKTsKICAgICAgICBsZXQgcGF5bWVudFRvdGFsID0gYXBpLkJpZ051bWJlcigwKTsKICAgICAgICBsZXQgc29sZE5mdHMgPSBbXTsKICAgICAgICBjb25zdCBzZWxsZXJzID0gW107CiAgICAgICAgY29uc3Qgc2VsbGVyTWFwID0ge307CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBvcmRlcnMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICAgIGNvbnN0IG9yZGVyID0gb3JkZXJzW2ldOwogICAgICAgICAgY29uc3QgZmluYWxQcmljZSA9IGFwaS5CaWdOdW1iZXIob3JkZXIucHJpY2UpOwogICAgICAgICAgY29uc3QgZmVlUGVyY2VudCA9IG9yZGVyLmZlZSAvIDEwMDAwOwogICAgICAgICAgbGV0IGZpbmFsRmVlID0gZmluYWxQcmljZS5tdWx0aXBsaWVkQnkoZmVlUGVyY2VudCkuZGVjaW1hbFBsYWNlcyh0b2tlbi5wcmVjaXNpb24pOwogICAgICAgICAgaWYgKGZpbmFsRmVlLmd0KGZpbmFsUHJpY2UpKSB7CiAgICAgICAgICAgIGZpbmFsRmVlID0gZmluYWxQcmljZTsgLy8gdW5saWtlbHkgYnV0IG5lZWQgdG8gYmUgc3VyZQogICAgICAgICAgfQogICAgICAgICAgbGV0IGZpbmFsUGF5bWVudCA9IGZpbmFsUHJpY2UubWludXMoZmluYWxGZWUpLmRlY2ltYWxQbGFjZXModG9rZW4ucHJlY2lzaW9uKTsKICAgICAgICAgIGlmIChmaW5hbFBheW1lbnQubHQoMCkpIHsKICAgICAgICAgICAgZmluYWxQYXltZW50ID0gYXBpLkJpZ051bWJlcigwKTsgLy8gdW5saWtlbHkgYnV0IG5lZWQgdG8gYmUgc3VyZQogICAgICAgICAgfQogICAgICAgICAgcGF5bWVudFRvdGFsID0gcGF5bWVudFRvdGFsLnBsdXMoZmluYWxQYXltZW50KTsKICAgICAgICAgIGZlZVRvdGFsID0gZmVlVG90YWwucGx1cyhmaW5hbEZlZSk7CgogICAgICAgICAgY29uc3Qga2V5ID0gbWFrZU1hcEtleShvcmRlci5hY2NvdW50LCBvcmRlci5vd25lZEJ5KTsKICAgICAgICAgIGNvbnN0IHNlbGxlckluZm8gPSBrZXkgaW4gc2VsbGVyTWFwCiAgICAgICAgICAgID8gc2VsbGVyTWFwW2tleV0KICAgICAgICAgICAgOiB7CiAgICAgICAgICAgICAgYWNjb3VudDogb3JkZXIuYWNjb3VudCwKICAgICAgICAgICAgICBvd25lZEJ5OiBvcmRlci5vd25lZEJ5LAogICAgICAgICAgICAgIG5mdElkczogW10sCiAgICAgICAgICAgICAgcGF5bWVudFRvdGFsOiBhcGkuQmlnTnVtYmVyKDApLAogICAgICAgICAgICB9OwoKICAgICAgICAgIHNlbGxlckluZm8ucGF5bWVudFRvdGFsID0gc2VsbGVySW5mby5wYXltZW50VG90YWwucGx1cyhmaW5hbFBheW1lbnQpOwogICAgICAgICAgc2VsbGVySW5mby5uZnRJZHMucHVzaChvcmRlci5uZnRJZCk7CiAgICAgICAgICBzZWxsZXJNYX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WN0aXZlS2V5LAogICAgICAgICAgfSk7CiAgICAgICAgICBpZiAoIWFwaS5hc3NlcnQoaXNUb2tlblRyYW5zZmVyVmVyaWZpZWQocmVzLCBhcGkuc2VuZGVyLCBmaW5hbE1hcmtldEFjY291bnQsIHByaWNlU3ltYm9sLCBmZWVUb3RhbCwgJ3RyYW5zZmVyJyksICd1bmFibGUgdG8gdHJhbnNmZXIgbWFya2V0IGZlZXMnKSkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyBzZW5kIHBheW1lbnRzIHRvIHNlbGxlcnMKICAgICAgICAvLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgbm8tcmVzdHJpY3RlZC1zeW50YXgKICAgICAgICBmb3IgKGNvbnN0IGluZm8gb2YgT2JqZWN0LnZhbHVlcyhzZWxsZXJNYXApKSB7CiAgICAgICAgICBpZiAoaW5mby5wYXltZW50VG90YWwuZ3QoMCkpIHsKICAgICAgICAgICAgY29uc3QgY29udHJhY3RBY3Rpb24gPSBpbmZvLm93bmVkQnkgPT09ICd1JyA/ICd0cmFuc2ZlcicgOiAndHJhbnNmZXJUb0NvbnRyYWN0JzsKICAgICAgICAgICAgaW5mby5wYXltZW50VG90YWwgPSBpbmZvLnBheW1lbnRUb3RhbC50b0ZpeGVkKHRva2VuLnByZWNpc2lvbik7CiAgICAgICAgICAgIGNvbnN0IHJlcyA9IGF3YWl0IGFwaS5leGVjdXRlU21hcnRDb250cmFjdCgndG9rZW5zJywgY29udHJhY3RBY3Rpb24sIHsKICAgICAgICAgICAgICB0bzogaW5mby5hY2NvdW50LCBzeW1ib2w6IHByaWNlU3ltYm9sLCBxdWFudGl0eTogaW5mby5wYXltZW50VG90YWwsIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChhcGkuYXNzZXJ0KGlzVG9rZW5UcmFuc2ZlclZlcmlmaWVkKHJlcywgYXBpLnNlbmRlciwgaW5mby5hY2NvdW50LCBwcmljZVN5bWJvbCwgaW5mby5wYXltZW50VG90YWwsIGNvbnRyYWN0QWN0aW9uKSwgYHVuYWJsZSB0byB0cmFuc2ZlciBwYXltZW50IHRvICR7aW5mby5hY2NvdW50fWApKSB7CiAgICAgICAgICAgICAgc29sZE5mdHMgPSBzb2xkTmZ0cy5jb25jYXQoaW5mby5uZnRJZHMpOwogICAgICAgICAgICAgIHNlbGxlcnMucHVzaChpbmZvKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc29sZE5mdHMgPSBzb2xkTmZ0cy5jb25jYXQoaW5mby5uZnRJZHMpOwogICAgICAgICAgICBzZWxsZXJzLnB1c2goaW5mbyk7CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyB0cmFuc2ZlciBzb2xkIE5GVCBpbnN0YW5jZXMgdG8gbmV3IG93bmVyCiAgICAgICAgY29uc3QgbmZ0QXJyYXkgPSBbXTsKICAgICAgICBjb25zdCB3cmFwcGVkTmZ0cyA9IHsKICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgIGlkczogc29sZE5mdHMsCiAgICAgICAgfTsKICAgICAgICBuZnRBcnJheS5wdXNoKHdyYXBwZWROZnRzKTsKICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICd0cmFuc2ZlcicsIHsKICAgICAgICAgIGZyb21UeXBlOiAnY29udHJhY3QnLAogICAgICAgICAgdG86IGFwaS5zZW5kZXIsCiAgICAgICAgICB0b1R5cGU6ICd1c2VyJywKICAgICAgICAgIG5mdHM6IG5mdEFycmF5LAogICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwoKICAgICAgICAvLyBkZWxldGUgc29sZCBtYXJrZXQgb3JkZXJzCiAgICAgICAgY29uc3QgZ3JvdXBpbmdNYXAgPSB7fTsKICAgICAgICBjb25zdCBzb2xkU2V0ID0gbmV3IFNldChzb2xkTmZ0cyk7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBvcmRlcnMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICAgIGNvbnN0IG9yZGVyID0gb3JkZXJzW2ldOwogICAgICAgICAgaWYgKHNvbGRTZXQuaGFzKG9yZGVyLm5mdElkKSkgewogICAgICAgICAgICBhd2FpdCBhcGkuZGIucmVtb3ZlKG1hcmtldFRhYmxlTmFtZSwgb3JkZXIpOwoKICAgICAgICAgICAgY29uc3Qga2V5ID0gbWFrZUdyb3VwaW5nS2V5KG9yZGVyLmdyb3VwaW5nLCBuZnQuZ3JvdXBCeSk7CiAgICAgICAgICAgIGNvbnN0IGdyb3VwSW5mbyA9IGtleSBpbiBncm91cGluZ01hcAogICAgICAgICAgICAgID8gZ3JvdXBpbmdNYXBba2V5XQogICAgICAgICAgICAgIDogewogICAgICAgICAgICAgICAgZ3JvdXBpbmc6IG9yZGVyLmdyb3VwaW5nLAogICAgICAgICAgICAgICAgaXNJbkNvbGxlY3Rpb246IGZhbHNlLAogICAgICAgICAgICAgICAgY291bnQ6IDAsCiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgZ3JvdXBJbmZvLmNvdW50IC09IDE7CiAgICAgICAgICAgIGdyb3VwaW5nTWFwW2tleV0gPSBncm91cEluZm87CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyBhZGQgdGhlIHRyYWRlIHRvIHRoZSBoaXN0b3J5CiAgICAgICAgYXdhaXQgdXBkYXRlVHJhZGVzSGlzdG9yeSgnYnV5JywgYXBpLnNlbmRlciwgJ3UnLCBzZWxsZXJzLCBzeW1ib2wsIHByaWNlU3ltYm9sLCByZXF1aXJlZEJhbGFuY2UsIGZpbmFsTWFya2V0QWNjb3VudCwgZmVlVG90YWwsIHNvbGROZnRzLmxlbmd0aCk7CgogICAgICAgIGFwaS5lbWl0KCdoaXRTZWxsT3JkZXInLCB7CiAgICAgICAg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SA9IG5ldyBEYXRlKGAke2FwaS5zdGVlbUJsb2NrVGltZXN0YW1wfS4wMDBaYCk7CiAgICAgICAgY29uc3QgdGltZXN0YW1wID0gYmxvY2tEYXRlLmdldFRpbWUoKTsKICAgICAgICBjb25zdCBmaW5hbFByaWNlID0gYXBpLkJpZ051bWJlcihwcmljZSkudG9GaXhlZCh0b2tlbi5wcmVjaXNpb24pOwogICAgICAgIGNvbnN0IG5mdEludGVnZXJJZExpc3QgPSBbXTsKICAgICAgICBjb25zdCBvcmRlckRhdGFNYXAgPSB7fTsKCiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCByZXMuZXZlbnRzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBjb25zdCBldiA9IHJlcy5ldmVudHNbaV07CiAgICAgICAgICBpZiAoZXYuY29udHJhY3QgJiYgZXYuZXZlbnQgJiYgZXYuZGF0YQogICAgICAgICAgICAmJiBldi5jb250cmFjdCA9PT0gJ25mdCcKICAgICAgICAgICAgJiYgZXYuZXZlbnQgPT09ICd0cmFuc2ZlcicKICAgICAgICAgICAgJiYgZXYuZGF0YS5mcm9tID09PSBhcGkuc2VuZGVyCiAgICAgICAgICAgICYmIGV2LmRhdGEuZnJvbVR5cGUgPT09ICd1JwogICAgICAgICAgICAmJiBldi5kYXRhLnRvID09PSBDT05UUkFDVF9OQU1FCiAgICAgICAgICAgICYmIGV2LmRhdGEudG9UeXBlID09PSAnYycKICAgICAgICAgICAgJiYgZXYuZGF0YS5zeW1ib2wgPT09IHN5bWJvbCkgewogICAgICAgICAgICAvLyB0cmFuc2ZlciBpcyB2ZXJpZmllZCwgbm93IHdlIGNhbiBhZGQgYSBtYXJrZXQgb3JkZXIKICAgICAgICAgICAgY29uc3QgaW5zdGFuY2VJZCA9IGV2LmRhdGEuaWQ7CgogICAgICAgICAgICBjb25zdCBvcmRlckRhdGEgPSB7CiAgICAgICAgICAgICAgbmZ0SWQ6IGluc3RhbmNlSWQsCiAgICAgICAgICAgICAgZ3JvdXBpbmc6IHt9LAogICAgICAgICAgICAgIGdyb3VwaW5nS2V5OiAnJywKICAgICAgICAgICAgfTsKICAgICAgICAgICAgY29uc3QgaW50ZWdlcklkID0gYXBpLkJpZ051bWJlcihpbnN0YW5jZUlkKS50b051bWJlcigpOwogICAgICAgICAgICBuZnRJbnRlZ2VySWRMaXN0LnB1c2goaW50ZWdlcklkKTsKICAgICAgICAgICAgb3JkZXJEYXRhTWFwW2ludGVnZXJJZF0gPSBvcmRlckRhdGE7CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyBxdWVyeSBORlQgaW5zdGFuY2VzIHRvIGNvbnN0cnVjdCB0aGUgZ3JvdXBpbmcKICAgICAgICBjb25zdCBpbnN0YW5jZXMgPSBhd2FpdCBhcGkuZGIuZmluZEluVGFibGUoCiAgICAgICAgICAnbmZ0JywKICAgICAgICAgIGluc3RhbmNlVGFibGVOYW1lLAogICAgICAgICAgewogICAgICAgICAgICBfaWQ6IHsKICAgICAgICAgICAgICAkaW46IG5mdEludGVnZXJJZExpc3QsCiAgICAgICAgICAgIH0sCiAgICAgICAgICB9LAogICAgICAgICAgTUFYX05VTV9VTklUU19PUEVSQUJMRSwKICAgICAgICAgIDAsCiAgICAgICAgICBbeyBpbmRleDogJ19pZCcsIGRlc2NlbmRpbmc6IGZhbHNlIH1dLAogICAgICAgICk7CgogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5zdGFuY2VzLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBjb25zdCBpbnN0YW5jZSA9IGluc3RhbmNlc1tqXTsKICAgICAgICAgIGNvbnN0IGdyb3VwaW5nID0ge307CiAgICAgICAgICBsZXQgZ3JvdXBpbmdLZXkgPSAnJzsKICAgICAgICAgIG5mdC5ncm91cEJ5LmZvckVhY2goKG5hbWUpID0+IHsKICAgICAgICAgICAgaWYgKGluc3RhbmNlLnByb3BlcnRpZXNbbmFtZV0gIT09IHVuZGVmaW5lZCAmJiBpbnN0YW5jZS5wcm9wZXJ0aWVzW25hbWVdICE9PSBudWxsKSB7CiAgICAgICAgICAgICAgZ3JvdXBpbmdbbmFtZV0gPSBpbnN0YW5jZS5wcm9wZXJ0aWVzW25hbWVdLnRvU3RyaW5nKCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZ3JvdXBpbmdbbmFtZV0gPSAnJzsKICAgICAgICAgICAgfQogICAgICAgICAgICBncm91cGluZ0tleSA9IGdyb3VwaW5nS2V5ICsgJzonICsgbmFtZSArICc6JyArIGdyb3VwaW5nW25hbWVdOwogICAgICAgICAgfSk7CiAgICAgICAgICBvcmRlckRhdGFNYXBbaW5zdGFuY2UuX2lkXS5ncm91cGluZyA9IGdyb3VwaW5nOwogICAgICAgICAgb3JkZXJEYXRhTWFwW2luc3RhbmNlLl9pZF0uZ3JvdXBpbmdLZXkgPSBncm91cGluZ0tleTsKICAgICAgICB9CgogICAgICAgIC8vIGNyZWF0ZSB0aGUgb3JkZXJzCiAgICAgICAgY29uc3QgZ3JvdXBpbmdNYXAgPSB7fTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IG5mdEludGVnZXJJZExpc3QubGVuZ3RoOyBrICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGludElkID0gbmZ0SW50ZWdlcklkTGlzdFtrXTsKICAgICAgICAgIGNvbnN0IG9yZGVySW5mbyA9IG9yZGVyRGF0YU1hcFtpbnRJZF07CiAgICAgICAgICBjb25zdCBvcmRlciA9IHsKICAgICAgICAgICAgYWNjb3VudDogYXBpLnNlbmRlciwKICAgICAgICAgICAgb3duZWRCeTogJ3UnLAogICAgICAgICAgICBuZnRJZDogb3JkZXJJbmZvLm5mdElkLAogICAgICAgICAgICBncm91cGluZzogb3JkZXJJbmZvLmdyb3VwaW5nLAogICAgICAgICAgICB0aW1lc3RhbXAsCiAgICAgICAgICAgIHByaWNlOiBmaW5hbFByaWNlLAogICAgICAgICAgICBwcmljZURlYzogeyAkbnVtYmVyRGVjaW1hbDogZmluYWxQcmljZSB9LAogICAgICAgICAgICBwcmljZVN5bWJvbCwKICAgICAgICAgICAgZmVlLAogICAgICAgICAgfTsKCiAgICAgICAgICBjb25zdCByZXN1bHQgPSBhd2FpdCBhcGkuZGIuaW5zZXJ0KG1hcmtldFRhYmxlTmFtZSwgb3JkZXIpOwoKICAgICAgICAgIGFwaS5lbWl0KCdzZWxsT3JkZXInLCB7CiAgICAgICAgICAgIGFjY291bnQ6IG9yZGVyLmFjY291bnQsCiAgICAgICAgICAgIG93bmVkQnk6IG9yZGVyLm93bmVkQnksCiAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgbmZ0SWQ6IG9yZGVyLm5mdElkLAogICAgICAgICAgICB0aW1lc3RhbXAsCiAgICAgICAgICAgIHByaWNlOiBvcmRlci5wcmljZSwKICAgICAgICAgICAgcHJpY2VTeW1ib2w6IG9yZGVyLnByaWNlU3ltYm9sLAogICAgICAgICAgICBmZWUsCiAgICAgICAgICAgIG9yZGVySWQ6IHJlc3VsdC5faWQsCiAgICAgICAgICB9KTsKCiAgICAgICAgICBjb25zdCBncm91cEluZm8gPSBvcmRlckluZm8uZ3JvdXBpbmdLZXkgaW4gZ3JvdXBpbmdNYXAKICAgICAgICAgICAgPyBncm91cGluZ01hcFtvcmRlckluZm8uZ3JvdXBpbmdLZXldCiAgICAgICAgICAgIDogewogICAgICAgICAgICAgIGdyb3VwaW5nOiBvcmRlckluZm8uZ3JvdXBpbmcsCiAgICAgICAgICAgICAgaXNJbkNvbGxlY3Rpb246IGZhbHNlLAogICAgICAgICAgICAgIGNvdW50OiAwLAogICAgICAgICAgICB9OwogICAgICAgICAgZ3JvdXBJbmZvLmNvdW50ICs9IDE7CiAgICAgICAgICBncm91cGluZ01hcFtvcmRlckluZm8uZ3JvdXBpbmdLZXldID0gZ3JvdXBJbmZvOwogICAgICAgIH0KCiAgICAgICAgLy8gdXBkYXRlIG9wZW4gaW50ZXJlc3QgbWV0cmljcwogICAgICAgIGF3YWl0IHVwZGF0ZU9wZW5JbnRlcmVzdCgnc2VsbCcsIHN5bWJvbCwgcHJpY2VTeW1ib2wsIGdyb3VwaW5nTWFwLCBuZnQuZ3JvdXBCeSk7CiAgICAgIH0KICAgIH0KICB9Cn07Cg==" } } }
test comment
test comment 2
edited comment
test reply
test comment 5
It's hard to say, but The ENIAC is regarded as the first 'real' computer. It was developed at University of Pennsylvania in 1946.
another comment
yes, marx had made some interesting observations.
test
test 7
test 73
test 75
test !zè§!èz
etrtrt
post test comment
***test
test dffdgerter
test
test comment
test comment
##STEEMCONTRACTSBEGIN##CONTRACTNAME##CONTRACTACTION##PAYLOAD##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract'##hello##{ "name": "Harpagon" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract##hello##{ "name": "Harpagon" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##if(payload&&payload.name&&'string'==typeof payload.name){const a='Hello '+payload.name;db.greetings=db.greetings?db.greetings:db.greetings=[],db.greetings.push(a)}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract", "code": "if(payload&&payload.name&&'string'==typeof payload.name){const a='Hello '+payload.name;db.greetings=db.greetings?db.greetings:db.greetings=[],db.greetings.push(a)}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract##hello##{ "name": "Harpagon" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(a){const{username:b}=a;if(b&&'string'==typeof b){let c=db.getTable('users'),d=db.findJsonPath(c,
$..[?(@.id == '\${sender}')]
);if(d);else{const e={id:sender,username:b};c.push(e)}}},actions.updateUser=function(a){const{username:b}=a;if(b&&'string'==typeof b){let c=db.getTable('users'),d=db.findJsonPath(c,$..[?(@.id == '\${sender}')]
);d&&(d.username=b)}},actions.removeUser=function(a){if(sender==owner){const{userId:b}=a;if(b&&'string'==typeof b){let c=db.getTable('users');const d=c.findIndex(e=>e.id===b);-1!=d&&c.splice(d,1)}}};"}##STEEMCONTRACTSEND####STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,`$..[?(@.id=='${sender}')]`);if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,`$..[?(@.id=='${sender}')]`);if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "account",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9"
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "token",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBkYi5jcmVhdGVUYWJsZSgndG9rZW5zJyk7CiAgICAgIGRiLmNyZWF0ZVRhYmxlKCdiYWxhbmNlcycpOwogICAgfQogICAgCiAgICBhY3Rpb25zLmNyZWF0ZSA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgICAgIGNvbnN0IHsgc3ltYm9sLCBwcmVjaXNpb24sIG1heFN1cHBseSB9ID0gcGF5bG9hZDsKICAgIAogICAgICBpZiAoc3ltYm9sICYmIHR5cGVvZiBzeW1ib2wgPT09ICdzdHJpbmcnCiAgICAgICAgJiYgKHByZWNpc2lvbiAmJiB0eXBlb2YgcHJlY2lzaW9uID09PSAnbnVtYmVyJyB8fCBwcmVjaXNpb24gPT09IDApCiAgICAgICAgJiYgbWF4U3VwcGx5ICYmIHR5cGVvZiBtYXhTdXBwbHkgPT09ICdudW1iZXInKSB7CiAgICAKICAgICAgICBjb25zdCBSZWdleFB1cmVMZXR0ZXJzID0gL15bYS16QS1aXSskLzsKICAgICAgICAKICAgICAgICAvLyB0aGUgc3ltYm9sIG11c3QgYmUgbWFkZSBvZiBsZXR0ZXJzIG9ubHkKICAgICAgICAvLyB0aGUgcHJlY2lzaW9uIG11c3QgYmUgYmV0d2VlbiAwIGFuZCA4IGFuZCBtdXN0IGJlIGFuIGludGVnZXIKICAgICAgICAvLyB0aGUgbWF4IHN1cHBseSBtdXN0IGJlIHBvc2l0aXZlCiAgICAgICAgaWYoYXNzZXJ0KFJlZ2V4UHVyZUxldHRlcnMudGVzdChzeW1ib2wpLCAnaW52YWxpZCBzeW1ib2wnKQogICAgICAgICAgJiYgYXNzZXJ0KChwcmVjaXNpb24gPj0gMCAmJiBwcmVjaXNpb24gPD0gOCkgJiYgKE51bWJlci5pc0ludGVnZXIocHJlY2lzaW9uKSksICdpbnZhbGlkIHByZWNpc2lvbicpCiAgICAgICAgICAmJiBhc3NlcnQobWF4U3VwcGx5ID4gMCwgJ21heFN1cHBseSBtdXN0IGJlIHBvc2l0aXZlJykpIHsKICAgICAgICAgICAgbGV0IHRva2VucyA9IGRiLmdldFRhYmxlKCd0b2tlbnMnKTsKICAgIAogICAgICAgICAgICAvLyBjaGVjayBpZiB0aGUgdG9rZW4gYWxyZWFkeSBleGlzdHMKICAgICAgICAgICAgbGV0IHRva2VuID0gdG9rZW5zLmZpbmRPbmUoeyBzeW1ib2wgfSk7CiAgICAKICAgICAgICAgICAgaWYgKGFzc2VydCh0b2tlbiA9PT0gbnVsbCwgJ3N5bWJvbCBhbHJlYWR5IGV4aXN0cycpKSB7IAogICAgICAgICAgICAgIGNvbnN0IG5ld1Rva2VuID0gewogICAgICAgICAgICAgICAgJ2lzc3Vlcic6IHNlbmRlciwKICAgICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICAgIHByZWNpc2lvbiwKICAgICAgICAgICAgICAgIG1heFN1cHBseSwKICAgICAgICAgICAgICAgICdzdXBwbHknOiAwCiAgICAgICAgICAgICAgfTsKICAgICAgICAgIAogICAgICAgICAgICAgIHRva2Vucy5pbnNlcnQobmV3VG9rZW4pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMuaXNzdWUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5IH0gPSBwYXlsb2FkOwogICAgCiAgICAgIGlmICh0byAmJiB0eXBlb2YgdG8gPT09ICdzdHJpbmcnCiAgICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bW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FjY291bnQgbXVzdCBoYXZlIGJlZW4gcmVnaXN0ZXJlZCBiZWZvcmUKICAgICAgICAgICAgaWYgKGFzc2VydChhY2NvdW50ICE9PSBudWxsLCAndG8gYWNjb3VudCBkb2VzIG5vdCBleGlzdCcpKSB7CiAgICAgICAgICAgICAgLy8gd2UgbWFkZSBhbGwgdGhlIHJlcXVpcmVkIHZlcmlmaWNhdGlvbiwgbGV0J3Mgbm93IGlzc3VlIHRoZSB0b2tlbnMKICAgIAogICAgICAgICAgICAgIHRva2VuLnN1cHBseSA9IGNhbGN1bGF0ZUJhbGFuY2UodG9rZW4uc3VwcGx5LCBxdWFudGl0eSwgdG9rZW4ucHJlY2lzaW9uLCB0cnVlKTsKICAgICAgICAgICAgICB0b2tlbnMudXBkYXRlKHRva2VuKTsKICAgICAgICAgICAgICAKICAgICAgICAgICAgICBhZGRCYWxhbmNlKHRva2VuLmlzc3VlciwgdG9rZW4sIHF1YW50aXR5KTsKICAgIAogICAgICAgICAgICAgIGlmKHRvICE9PSB0b2tlbi5pc3N1ZXIpIHsKICAgICAgICAgICAgICAgIGFjdGlvbnMudHJhbnNmZXIocGF5bG9hZCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMudHJhbnNmZXIgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5IH0gPSBwYXlsb2FkOwogICAgCiAgICAgIGlmICh0byAmJiB0eXBlb2YgdG8gPT09ICdzdHJpbmcnCiAgICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bWJvbCA9PT0gJ3N0cmluZycKICAgICAgICAgICYmIHF1YW50aXR5ICYmIHR5cGVvZiBxdWFudGl0eSA9PT0gJ251bWJlcicpIHsKICAgIAogICAgICAgIGlmIChhc3NlcnQodG8gIT09IHNlbmRlciwgJ2Nhbm5vdCB0cmFuc2ZlciB0byBzZWxmJykpIHsKICAgICAgICAgIGxldCBhY2NvdW50ID0gZGIuZmluZE9uZUluVGFibGUoJ2FjY291bnQnLCAnYWNjb3VudHMnLCB7ICdpZCc6IHRvIH0pOwogICAgCiAgICAgICAgICAvLyB0aGUgYWNjb3VudCBtdXN0IGhhdmUgYmVlbiByZWdpc3RlcmVkIGJlZm9yZQogICAgICAgICAgaWYgKGFzc2VydChhY2NvdW50ICE9PSBudWxsLCAndG8gYWNjb3VudCBkb2VzIG5vdCBleGlzdCcpKSB7CiAgICAgICAgICAgIGxldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAgICAgICAgIGxldCB0b2tlbiA9IHRva2Vucy5maW5kT25lKHsgc3ltYm9sIH0pOwogICAgCiAgICAgICAgICAgIC8vIHRoZSBzeW1ib2wgbXVzdCBleGlzdAogICAgICAgICAgICAvLyB0aGVuIHdlIG5lZWQgdG8gY2hlY2sgdGhhdCB0aGUgcXVhbnRpdHkgaXMgY29ycmVjdAogICAgICAgICAgICBpZiAoYXNzZXJ0KHRva2VuICE9PSBudWxsLCAnc3ltYm9sIGRvZXMgbm90IGV4aXN0JykKICAgICAgICAgICAgICAgICYmIGFzc2VydChjb3VudERlY2ltYWxzKHF1YW50aXR5KSA8PSB0b2tlbi5wcmVjaXNpb24sICdzeW1ib2wgcHJlY2lzaW9uIG1pc21hdGNoJykKICAgICAgICAgICAgICAgICYmIGFzc2VydChxdWFudGl0eSA+IDAsICdtdXN0IHRyYW5zZmVyIHBvc2l0aXZlIHF1YW50aXR5JykpIHsKICAgICAgICAgICAgICAKICAgICAgICAgICAgICBpZiAoc3ViQmFsYW5jZShzZW5kZXIsIHRva2VuLCBxdWFudGl0eSkpIHsKICAgICAgICAgICAgICAgIGFkZEJhbGFuY2UodG8sIHRva2VuLCBxdWFudGl0eSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9Ci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gdmFsdWUudG9TdHJpbmcoKS5zcGxpdCgnLicpWzFdLmxlbmd0aCB8fCAwOyAKICAgIH0="
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "account2",
"contractAction": "register",
"contractPayload": {}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961g",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "account",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9"
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961g",
"json": {
"contractName": "account",
"contractAction": "register",
"contractPayload": {}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "account",
"contractAction": "register",
"contractPayload": {}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "token",
"contractAction": "create",
"contractPayload": {
"symbol": "PKTC",
"precision": 0,
"maxSupply": 1000000
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "token",
"contractAction": "issue",
"contractPayload": {
"symbol": "PKTC",
"to": "harpagon",
"quantity": 100
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "token",
"contractAction": "issue",
"contractPayload": {
"symbol": "PKTC",
"to": "harpagon",
"quantity": 900
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961g",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "token",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCd0b2tlbnMnKTsKICBkYi5jcmVhdGVUYWJsZSgnYmFsYW5jZXMnKTsKfQoKYWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGNvbnN0IHsgc3ltYm9sLCBwcmVjaXNpb24sIG1heFN1cHBseSB9ID0gcGF5bG9hZDsKCiAgaWYgKHN5bWJvbCAmJiB0eXBlb2Ygc3ltYm9sID09PSAnc3RyaW5nJwogICAgJiYgKHByZWNpc2lvbiAmJiB0eXBlb2YgcHJlY2lzaW9uID09PSAnbnVtYmVyJyB8fCBwcmVjaXNpb24gPT09IDApCiAgICAmJiBtYXhTdXBwbHkgJiYgdHlwZW9mIG1heFN1cHBseSA9PT0gJ251bWJlcicpIHsKCiAgICBjb25zdCBSZWdleFB1cmVMZXR0ZXJzID0gL15bYS16QS1aXSskLzsKCiAgICAvLyB0aGUgc3ltYm9sIG11c3QgYmUgbWFkZSBvZiBsZXR0ZXJzIG9ubHkKICAgIC8vIHRoZSBwcmVjaXNpb24gbXVzdCBiZSBiZXR3ZWVuIDAgYW5kIDggYW5kIG11c3QgYmUgYW4gaW50ZWdlcgogICAgLy8gdGhlIG1heCBzdXBwbHkgbXVzdCBiZSBwb3NpdGl2ZQogICAgaWYgKGFzc2VydChSZWdleFB1cmVMZXR0ZXJzLnRlc3Qoc3ltYm9sKSwgJ2ludmFsaWQgc3ltYm9sJyk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ByYXRlID0gTWF0aC5wb3coMTAsIHByZWNpc2lvbik7CiAgbGV0IHRtcFF0eSA9IHF1YW50aXR5ICogcmF0ZTsKICBsZXQgdG1wQmFsYW5jZSA9IGJhbGFuY2UgKiByYXRlOwoKICByZXR1cm4gYWRkID8gKHRtcEJhbGFuY2UgKyB0bXBRdHkpIC8gcmF0ZSA6ICh0bXBCYWxhbmNlIC0gdG1wUXR5KSAvIHJhdGU7Cn0KCmxldCBjb3VudERlY2ltYWxzID0gZnVuY3Rpb24gKHZhbHVlKSB7CiAgaWYgKE1hdGguZmxvb3IodmFsdWUpID09PSB2YWx1ZSkgcmV0dXJuIDA7CiAgcmV0dXJuIHZhbHVlLnRvU3RyaW5nKCkuc3BsaXQoJy4nKVsxXS5sZW5ndGggfHwgMDsKfQ=="
}
}
}
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user){}else{const newUser={"id":sender,"username":username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==="string"){let users=db.getTable("users");const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": 'actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user){}else{const newUser={"id":sender,"username":username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==="string"){let users=db.getTable("users");let user=db.findJsonPath(users,"$..[?(@.id == '"+sender+"')]");if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==="string"){let users=db.getTable("users");const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}'}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,'$..[?(@.id == ''+sender+'')]');if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,'$..[?(@.id == ''+sender+'')]');if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "actions.addUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,'$..[?(@.id == ''+sender+'')]');if(user){}else{const newUser={'id':sender,'username':username};users.push(newUser)}}}actions.updateUser=function(payload){const{username}=payload;if(username&&typeof username==='string'){let users=db.getTable('users');let user=db.findJsonPath(users,'$..[?(@.id == ''+sender+'')]');if(user)user.username=username}}actions.removeUser=function(payload){if(sender!=owner)return;const{userId}=payload;if(userId&&typeof userId==='string'){let users=db.getTable('users');const index=users.findIndex(user=>user.id===userId);if(index!=-1)users.splice(index,1)}}"}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "test_contract_users", "code": "YWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgIGlmICh1c2VybmFtZSAmJiB0eXBlb2YgdXNlcm5hbWUgPT09ICdzdHJpbmcnKXsNCg0KICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgIGxldCB1c2VyID0gZGIuZmluZEpzb25QYXRoKHVzZXJzLCBgJC4uWz8oQC5pZCA9PSAnXCR7c2VuZGVyfScpXWApOw0KDQogICAgICBpZiAodXNlcikgew0KICAgICAgICAvLyB1c2VyIGFscmVhZHkgZXhpc3RzDQogICAgICB9IGVsc2Ugew0KICAgICAgICBjb25zdCBuZXdVc2VyID0gew0KICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAndXNlcm5hbWUnOiB1c2VybmFtZQ0KICAgICAgICB9Ow0KICAgICAgICB1c2Vycy5wdXNoKG5ld1VzZXIpOw0KICAgICAgfQ0KICAgIH0NCiAgfQ0KDQogIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgY29uc3QgeyB1c2VybmFtZSB9ID0gcGF5bG9hZDsNCiAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgbGV0IHVzZXIgPSBkYi5maW5kSnNvblBhdGgodXNlcnMsIGAkLi5bPyhALmlkID09ICdcJHtzZW5kZXJ9JyldYCk7DQogICAgICBpZiAodXNlcikNCiAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgIH0NCiAgfQ0KDQogIGFjdGlvbnMucmVtb3ZlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgaWYgKHNlbmRlciAhPSBvd25lcikgcmV0dXJuOw0KICAgIA0KICAgIGNvbnN0IHsgdXNlcklkIH0gPSBwYXlsb2FkOw0KDQogICAgaWYgKHVzZXJJZCAmJiB0eXBlb2YgdXNlcklkID09PSAnc3RyaW5nJyl7DQogICAgICBsZXQgdXNlcnMgPSBkYi5nZXRUYWJsZSgndXNlcnMnKTsNCiAgICAgIGNvbnN0IGluZGV4ID0gdXNlcnMuZmluZEluZGV4KHVzZXIgPT4gdXNlci5pZCA9PT0gdXNlcklkKTsNCiAgICAgIGlmIChpbmRleCAhPSAtMSkNCiAgICAgICAgdXNlcnMuc3BsaWNlKGluZGV4LCAxKTsNCiAgICB9DQogIH0="}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##test_contract_users##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "users_contract", "code": "YWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgew0KICAgICAgZGIuY3JlYXRlVGFibGUoJ3VzZXJzJyk7DQogICAgfQ0KDQogICAgYWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICAgIGNvbnN0IHsgdXNlcm5hbWUgfSA9IHBheWxvYWQ7DQogICAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgICAgbGV0IHVzZXIgPSB1c2Vycy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOw0KDQogICAgICAgIGlmICh1c2VyID09PSBudWxsKSB7DQogICAgICAgICAgY29uc3QgbmV3VXNlciA9IHsNCiAgICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAgICd1c2VybmFtZSc6IHVzZXJuYW1lLA0KICAgICAgICAgICAgJ3ZlcmlmaWVkJzogZmFsc2UsDQogICAgICAgICAgfTsNCg0KICAgICAgICAgIHVzZXJzLmluc2VydChuZXdVc2VyKTsNCiAgICAgICAgICBlbWl0KCduZXdVc2VyQ3JlYXRlZCcsIG5ld1VzZXIpOw0KICAgICAgICB9IA0KICAgICAgfQ0KICAgIH0NCg0KICAgIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgICAgaWYgKHVzZXJuYW1lICYmIHR5cGVvZiB1c2VybmFtZSA9PT0gJ3N0cmluZycpew0KDQogICAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgICBsZXQgdXNlciA9IHVzZXJzLmZpbmRPbmUoeyAnaWQnOiBzZW5kZXIgfSk7DQogICAgICAgIGlmICh1c2VyKSB7DQogICAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgICAgICAgIHVzZXJzLnVwZGF0ZSh1c2VyKTsNCiAgICAgICAgfQ0KICAgICAgfQ0KICAgIH0="##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##users_contract##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "users_contract", "code": "YWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgew0KICAgICAgZGIuY3JlYXRlVGFibGUoJ3VzZXJzJyk7DQogICAgfQ0KDQogICAgYWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICAgIGNvbnN0IHsgdXNlcm5hbWUgfSA9IHBheWxvYWQ7DQogICAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgICAgbGV0IHVzZXIgPSB1c2Vycy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOw0KDQogICAgICAgIGlmICh1c2VyID09PSBudWxsKSB7DQogICAgICAgICAgY29uc3QgbmV3VXNlciA9IHsNCiAgICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAgICd1c2VybmFtZSc6IHVzZXJuYW1lLA0KICAgICAgICAgICAgJ3ZlcmlmaWVkJzogZmFsc2UsDQogICAgICAgICAgfTsNCg0KICAgICAgICAgIHVzZXJzLmluc2VydChuZXdVc2VyKTsNCiAgICAgICAgICBlbWl0KCduZXdVc2VyQ3JlYXRlZCcsIG5ld1VzZXIpOw0KICAgICAgICB9IA0KICAgICAgfQ0KICAgIH0NCg0KICAgIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgICAgaWYgKHVzZXJuYW1lICYmIHR5cGVvZiB1c2VybmFtZSA9PT0gJ3N0cmluZycpew0KDQogICAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgICBsZXQgdXNlciA9IHVzZXJzLmZpbmRPbmUoeyAnaWQnOiBzZW5kZXIgfSk7DQogICAgICAgIGlmICh1c2VyKSB7DQogICAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgICAgICAgIHVzZXJzLnVwZGF0ZSh1c2VyKTsNCiAgICAgICAgfQ0KICAgICAgfQ0KICAgIH0="}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##users_contract##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##contract##deploy##{"name": "users_test_contract", "code": "YWN0aW9ucy5jcmVhdGUgPSBmdW5jdGlvbiAocGF5bG9hZCkgew0KICAgICAgZGIuY3JlYXRlVGFibGUoJ3VzZXJzJyk7DQogICAgfQ0KDQogICAgYWN0aW9ucy5hZGRVc2VyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsNCiAgICAgIGNvbnN0IHsgdXNlcm5hbWUgfSA9IHBheWxvYWQ7DQogICAgICBpZiAodXNlcm5hbWUgJiYgdHlwZW9mIHVzZXJuYW1lID09PSAnc3RyaW5nJyl7DQoNCiAgICAgICAgbGV0IHVzZXJzID0gZGIuZ2V0VGFibGUoJ3VzZXJzJyk7DQoNCiAgICAgICAgbGV0IHVzZXIgPSB1c2Vycy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOw0KDQogICAgICAgIGlmICh1c2VyID09PSBudWxsKSB7DQogICAgICAgICAgY29uc3QgbmV3VXNlciA9IHsNCiAgICAgICAgICAgICdpZCc6IHNlbmRlciwNCiAgICAgICAgICAgICd1c2VybmFtZSc6IHVzZXJuYW1lLA0KICAgICAgICAgICAgJ3ZlcmlmaWVkJzogZmFsc2UsDQogICAgICAgICAgfTsNCg0KICAgICAgICAgIHVzZXJzLmluc2VydChuZXdVc2VyKTsNCiAgICAgICAgICBlbWl0KCduZXdVc2VyQ3JlYXRlZCcsIG5ld1VzZXIpOw0KICAgICAgICB9IA0KICAgICAgfQ0KICAgIH0NCg0KICAgIGFjdGlvbnMudXBkYXRlVXNlciA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7DQogICAgICBjb25zdCB7IHVzZXJuYW1lIH0gPSBwYXlsb2FkOw0KICAgICAgaWYgKHVzZXJuYW1lICYmIHR5cGVvZiB1c2VybmFtZSA9PT0gJ3N0cmluZycpew0KDQogICAgICAgIGxldCB1c2VycyA9IGRiLmdldFRhYmxlKCd1c2VycycpOw0KICAgICAgICBsZXQgdXNlciA9IHVzZXJzLmZpbmRPbmUoeyAnaWQnOiBzZW5kZXIgfSk7DQogICAgICAgIGlmICh1c2VyKSB7DQogICAgICAgICAgdXNlci51c2VybmFtZSA9IHVzZXJuYW1lOw0KICAgICAgICAgIHVzZXJzLnVwZGF0ZSh1c2VyKTsNCiAgICAgICAgfQ0KICAgICAgfQ0KICAgIH0="}##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##users_contract##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
##STEEMCONTRACTSBEGIN##users_test_contract##addUser##{ "username": "AwesomeUsername" }##STEEMCONTRACTSEND##
{
"id": "ssc-b8923f70-c1f7-497f-961d",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "account2",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9"
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961l",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "account",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9"
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961l",
"json": {
"contractName": "account",
"contractAction": "register",
"contractPayload": {}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961l",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "token",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBkYi5jcmVhdGVUYWJsZSgndG9rZW5zJyk7CiAgICAgIGRiLmNyZWF0ZVRhYmxlKCdiYWxhbmNlcycpOwogICAgfQogICAgCiAgICBhY3Rpb25zLmNyZWF0ZSA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgICAgIGNvbnN0IHsgc3ltYm9sLCBwcmVjaXNpb24sIG1heFN1cHBseSB9ID0gcGF5bG9hZDsKICAgIAogICAgICBpZiAoc3ltYm9sICYmIHR5cGVvZiBzeW1ib2wgPT09ICdzdHJpbmcnCiAgICAgICAgJiYgKHByZWNpc2lvbiAmJiB0eXBlb2YgcHJlY2lzaW9uID09PSAnbnVtYmVyJyB8fCBwcmVjaXNpb24gPT09IDApCiAgICAgICAgJiYgbWF4U3VwcGx5ICYmIHR5cGVvZiBtYXhTdXBwbHkgPT09ICdudW1iZXInKSB7CiAgICAKICAgICAgICBjb25zdCBSZWdleFB1cmVMZXR0ZXJzID0gL15bYS16QS1aXSskLzsKICAgIAogICAgICAgIC8vIHRoZSBzeW1ib2wgbXVzdCBiZSBtYWRlIG9mIGxldHRlcnMgb25seQogICAgICAgIC8vIHRoZSBwcmVjaXNpb24gbXVzdCBiZSBiZXR3ZWVuIDAgYW5kIDggYW5kIG11c3QgYmUgYW4gaW50ZWdlcgogICAgICAgIC8vIHRoZSBtYXggc3VwcGx5IG11c3QgYmUgcG9zaXRpdmUKICAgICAgICBpZiAoYXNzZXJ0KFJlZ2V4UHVyZUxldHRlcnMudGVzdChzeW1ib2wpLCAnaW52YWxpZCBzeW1ib2wnKQogICAgICAgICAgJiYgYXNzZXJ0KChwcmVjaXNpb24gPj0gMCAmJiBwcmVjaXNpb24gPD0gOCkgJiYgKE51bWJlci5pc0ludGVnZXIocHJlY2lzaW9uKSksICdpbnZhbGlkIHByZWNpc2lvbicpCiAgICAgICAgICAmJiBhc3NlcnQobWF4U3VwcGx5ID4gMCwgJ21heFN1cHBseSBtdXN0IGJlIHBvc2l0aXZlJykpIHsKICAgICAgICAgIGxldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAKICAgICAgICAgIC8vIGNoZWNrIGlmIHRoZSB0b2tlbiBhbHJlYWR5IGV4aXN0cwogICAgICAgICAgbGV0IHRva2VuID0gdG9rZW5zLmZpbmRPbmUoeyBzeW1ib2wgfSk7CiAgICAKICAgICAgICAgIGlmIChhc3NlcnQodG9rZW4gPT09IG51bGwsICdzeW1ib2wgYWxyZWFkeSBleGlzdHMnKSkgewogICAgICAgICAgICBjb25zdCBuZXdUb2tlbiA9IHsKICAgICAgICAgICAgICAnaXNzdWVyJzogc2VuZGVyLAogICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICBwcmVjaXNpb24sCiAgICAgICAgICAgICAgbWF4U3VwcGx5LAogICAgICAgICAgICAgICdzdXBwbHknOiAwCiAgICAgICAgICAgIH07CiAgICAKICAgICAgICAgICAgdG9rZW5zLmluc2VydChuZXdUb2tlbik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMuaXNzdWUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5LCBpc1NpZ25lZFdpdGhBY3RpdmVLZXkgfSA9IHBheWxvYWQ7CiAgICAKICAgICAgaWYgKGFzc2VydChpc1NpZ25lZFdpdGhBY3RpdmVLZXkgPT09IHRydWUsICd5b3UgbXVzdCB1c2UgYSBjdXN0b21fanNvbiBzaWduZWQgd2l0aCB5b3VyIGFjdGl2ZSBrZXknKQogICAgICAgICYmIHRvICYmIHR5cGVvZiB0byA9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BiYWxhbmNlcyA9IGRiLmdldFRhYmxlKCdiYWxhbmNlcycpOwogICAgICBsZXQgYmFsYW5jZSA9IGJhbGFuY2VzLmZpbmRPbmUoeyBhY2NvdW50LCAnc3ltYm9sJzogdG9rZW4uc3ltYm9sIH0pOwogICAgCiAgICAgIGlmIChiYWxhbmNlID09PSBudWxsKSB7CiAgICAgICAgYmFsYW5jZSA9IHsKICAgICAgICAgIGFjY291bnQsCiAgICAgICAgICAnc3ltYm9sJzogdG9rZW4uc3ltYm9sLAogICAgICAgICAgJ2JhbGFuY2UnOiBxdWFudGl0eQogICAgICAgIH0KICAgICAgICAKICAgICAgICBiYWxhbmNlcy5pbnNlcnQoYmFsYW5jZSk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgYmFsYW5jZS5iYWxhbmNlID0gY2FsY3VsYXRlQmFsYW5jZShiYWxhbmNlLmJhbGFuY2UsIHF1YW50aXR5LCB0b2tlbi5wcmVjaXNpb24sIHRydWUpOwogICAgCiAgICAgICAgYmFsYW5jZXMudXBkYXRlKGJhbGFuY2UpOwogICAgICB9CiAgICB9CiAgICAKICAgIGxldCBjYWxjdWxhdGVCYWxhbmNlID0gZnVuY3Rpb24gKGJhbGFuY2UsIHF1YW50aXR5LCBwcmVjaXNpb24sIGFkZCkgewogICAgICBpZiAocHJlY2lzaW9uID09PSAwKSB7CiAgICAgICAgcmV0dXJuIGFkZCA/IGJhbGFuY2UgKyBxdWFudGl0eSA6IGJhbGFuY2UgLSBxdWFudGl0eQogICAgICB9CiAgICAgIAogICAgICByZXR1cm4gYWRkID8gY3VycmVuY3koYmFsYW5jZSwgeyBwcmVjaXNpb24gfSkuc3VidHJhY3QocXVhbnRpdHkpIDogY3VycmVuY3koYmFsYW5jZSwgeyBwcmVjaXNpb24gfSkuc3VidHJhY3QocXVhbnRpdHkpOwogICAgfQogICAgCiAgICBsZXQgY291bnREZWNpbWFscyA9IGZ1bmN0aW9uICh2YWx1ZSkgewogICAgICBpZiAoTWF0aC5mbG9vcih2YWx1ZSkgPT09IHZhbHVlKSByZXR1cm4gMDsKICAgICAgcmV0dXJuIHZhbHVlLnRvU3RyaW5nKCkuc3BsaXQoJy4nKVsxXS5sZW5ndGggfHwgMDsKICAgIH0="
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961l",
"json": {
"contractName": "token",
"contractAction": "create",
"contractPayload": {
"symbol": "PKTC",
"precision": 0,
"maxSupply": 1000000
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "account",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGRiLmNyZWF0ZVRhYmxlKCdhY2NvdW50cycpOwp9CgovLyByZWdpc3RlciBhbiBhY2NvdW50IGhlbHBzIG90aGVyIGNvbnRyYWN0cyB0byBrbm93IAovLyBpZiBhbiBhY2NvdW50IGV4aXN0cyBvbiB0aGUgU3RlZW0gYmxvY2tjaGFpbgphY3Rpb25zLnJlZ2lzdGVyID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBsZXQgYWNjb3VudHMgPSBkYi5nZXRUYWJsZSgnYWNjb3VudHMnKTsKCiAgbGV0IGFjY291bnQgPSBhY2NvdW50cy5maW5kT25lKHsgJ2lkJzogc2VuZGVyIH0pOwoKICBpZiAoYWNjb3VudCA9PT0gbnVsbCkgewogICAgY29uc3QgbmV3QWNjb3VudCA9IHsKICAgICAgJ2lkJzogc2VuZGVyCiAgICB9OwoKICAgIGFjY291bnRzLmluc2VydChuZXdBY2NvdW50KTsKICB9IAp9"
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "account",
"contractAction": "register",
"contractPayload": {}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "token",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBmdW5jdGlvbiAocGF5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JykpIHsKICAgICAgICAgIGxldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAKICAgICAgICAgIC8vIGNoZWNrIGlmIHRoZSB0b2tlbiBhbHJlYWR5IGV4aXN0cwogICAgICAgICAgbGV0IHRva2VuID0gdG9rZW5zLmZpbmRPbmUoeyBzeW1ib2wgfSk7CiAgICAKICAgICAgICAgIGlmIChhc3NlcnQodG9rZW4gPT09IG51bGwsICdzeW1ib2wgYWxyZWFkeSBleGlzdHMnKSkgewogICAgICAgICAgICBjb25zdCBuZXdUb2tlbiA9IHsKICAgICAgICAgICAgICAnaXNzdWVyJzogc2VuZGVyLAogICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICBwcmVjaXNpb24sCiAgICAgICAgICAgICAgbWF4U3VwcGx5LAogICAgICAgICAgICAgICdzdXBwbHknOiAwCiAgICAgICAgICAgIH07CiAgICAKICAgICAgICAgICAgdG9rZW5zLmluc2VydChuZXdUb2tlbik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICAKICAgIGFjdGlvbnMuaXNzdWUgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogICAgICBjb25zdCB7IHRvLCBzeW1ib2wsIHF1YW50aXR5LCBpc1NpZ25lZFdpdGhBY3RpdmVLZXkgfSA9IHBheWxvYWQ7CiAgICAKICAgICAgaWYgKGFzc2VydChpc1NpZ25lZFdpdGhBY3RpdmVLZXkgPT09IHRydWUsICd5b3UgbXVzdCB1c2UgYSBjdXN0b21fanNvbiBzaWduZWQgd2l0aCB5b3VyIGFjdGl2ZSBrZXknKQogICAgICAgICYmIHRvICYmIHR5cGVvZiB0byA9PT0gJ3N0cmluZycKICAgICAgICAmJiBzeW1ib2wgJiYgdHlwZW9mIHN5bWJvbCA9PT0gJ3N0cmluZycKICAgICAgICAmJiBxdWFudGl0eSAmJiB0eXBlb2YgcXVhbnRpdHkgPT09ICdudW1iZXInKSB7CiAgICAKICAgICAg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cmFuc2ZlciB0byBzZWxmJykpIHsKICAgICAgICAgIGxldCBhY2NvdW50ID0gZGIuZmluZE9uZUluVGFibGUoJ2FjY291bnQnLCAnYWNjb3VudHMnLCB7ICdpZCc6IHRvIH0pOwogICAgCiAgICAgICAgICAvLyB0aGUgYWNjb3VudCBtdXN0IGhhdmUgYmVlbiByZWdpc3RlcmVkIGJlZm9yZQogICAgICAgICAgaWYgKGFzc2VydChhY2NvdW50ICE9PSBudWxsLCAndG8gYWNjb3VudCBkb2VzIG5vdCBleGlzdCcpKSB7CiAgICAgICAgICAgIGxldCB0b2tlbnMgPSBkYi5nZXRUYWJsZSgndG9rZW5zJyk7CiAgICAgICAgICAgIGxldCB0b2tlbiA9IHRva2Vucy5maW5kT25lKHsgc3ltYm9sIH0pOwogICAgCiAgICAgICAgICAgIC8vIHRoZSBzeW1ib2wgbXVzdCBleGlzdAogICAgICAgICAgICAvLyB0aGVuIHdlIG5lZWQgdG8gY2hlY2sgdGhhdCB0aGUgcXVhbnRpdHkgaXMgY29ycmVjdAogICAgICAgICAgICBpZiAoYXNzZXJ0KHRva2VuICE9PSBudWxsLCAnc3ltYm9sIGRvZXMgbm90IGV4aXN0JykKICAgICAgICAgICAgICAmJiBhc3NlcnQoY291bnREZWNpbWFscyhxdWFudGl0eSkgPD0gdG9rZW4ucHJlY2lzaW9uLCAnc3ltYm9sIHByZWNpc2lvbiBtaXNtYXRjaCcpCiAgICAgICAgICAgICAgJiYgYXNzZXJ0KHF1YW50aXR5ID4gMCwgJ211c3QgdHJhbnNmZXIgcG9zaXRpdmUgcXVhbnRpdHknKSkgewogICAgCiAgICAgICAgICAgICAgaWYgKHN1YkJhbGFuY2Uoc2VuZGVyLCB0b2tlbiwgcXVhbnRpdHkpKSB7CiAgICAgICAgICAgICAgICBhZGRCYWxhbmNlKHRvLCB0b2tlbiwgcXVhbnRpdHkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgf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GlmIChiYWxhbmNlID09PSBudWxsKSB7CiAgICAgICAgYmFsYW5jZSA9IHsKICAgICAgICAgIGFjY291bnQsCiAgICAgICAgICAnc3ltYm9sJzogdG9rZW4uc3ltYm9sLAogICAgICAgICAgJ2JhbGFuY2UnOiBxdWFudGl0eQogICAgICAgIH0KICAgICAgICAKICAgICAgICBiYWxhbmNlcy5pbnNlcnQoYmFsYW5jZSk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgYmFsYW5jZS5iYWxhbmNlID0gY2FsY3VsYXRlQmFsYW5jZShiYWxhbmNlLmJhbGFuY2UsIHF1YW50aXR5LCB0b2tlbi5wcmVjaXNpb24sIHRydWUpOwogICAgCiAgICAgICAgYmFsYW5jZXMudXBkYXRlKGJhbGFuY2UpOwogICAgICB9CiAgICB9CiAgICAKICAgIGxldCBjYWxjdWxhdGVCYWxhbmNlID0gZnVuY3Rpb24gKGJhbGFuY2UsIHF1YW50aXR5LCBwcmVjaXNpb24sIGFkZCkgewogICAgICBpZiAocHJlY2lzaW9uID09PSAwKSB7CiAgICAgICAgcmV0dXJuIGFkZCA/IGJhbGFuY2UgKyBxdWFudGl0eSA6IGJhbGFuY2UgLSBxdWFudGl0eQogICAgICB9CgogICAgICByZXR1cm4gYWRkID8gY3VycmVuY3koYmFsYW5jZSwgeyBwcmVjaXNpb24gfSkuYWRkKHF1YW50aXR5KSA6IGN1cnJlbmN5KGJhbGFuY2UsIHsgcHJlY2lzaW9uIH0pLnN1YnRyYWN0KHF1YW50aXR5KTsKICAgIH0KICAgIAogICAgbGV0IGNvdW50RGVjaW1hbHMgPSBmdW5jdGlvbiAodmFsdWUpIHsKICAgICAgaWYgKE1hdGguZmxvb3IodmFsdWUpID09PSB2YWx1ZSkgcmV0dXJuIDA7CiAgICAgIHJldHVybiB2YWx1ZS50b1N0cmluZygpLnNwbGl0KCcuJylbMV0ubGVuZ3RoIHx8IDA7CiAgICB9"
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "token",
"contractAction": "create",
"contractPayload": {
"symbol": "PKTC",
"precision": 0,
"maxSupply": 1000000
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "token",
"contractAction": "create",
"contractPayload": {
"symbol": "SMMT",
"precision": 0,
"maxSupply": 1000000
}
}
}
{
"id": "ssc-b8923f70-c1f7-497f-961j",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "smmt",
"code": "Y29uc3QgVE9LRU5TWU1CT0wgPSAnU01NVCc7CmFjdGlvbnMuY3JlYXRlU1NDID0gZnVuY3Rpb24gKHBheWxvYWQpIHsKICBkYi5jcmVhdGVUYWJsZSgnYmFsYW5jZXMnKTsKICBsZXQgcmV3YXJkcyA9IGRiLmNyZWF0ZVRhYmxlKCdyZXdhcmRzJyk7CiAgcmV3YXJkcy5pbnNlcnQoewogICAgJ3BlbmRpbmdSZXdhcmRzJzogMCwKICAgICdyZXdhcmRzRGlzdHJpYnV0aW9uSW50ZXJ2YWwnOiAzMDAwMCwKICAgICdsYXN0QmxvY2tSZXdhcmQnOiAwLAogICAgJ3Rva2VuSXNzdWFuY2VSYXRlJzogMSwKICAgICduZXh0SGFsdmluZyc6IDUwMDAwMCwKICAgICdiZW5lZmljaWFyaWVzJzogWydzdGVlbW1vbnN0ZXJzJywgJ2hhcnBhZ29uJ10KICB9KQp9CgphY3Rpb25zLnVwZGF0ZVJld2FyZHNEaXN0cmlidXRpb25JbnRlcnZhbCA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgaWYgKHNlbmRlciAhPT0gb3duZXIpIHJldHVybjsKCiAgY29uc3QgeyBuYkJsb2NrcyB9ID0gcGF5bG9hZDsKCiAgaWYgKE51bWJlci5pc0ludGVnZXIobmJCbG9ja3MpKSB7CiAgICBsZXQgcmV3YXJkcyA9IGRiLmdldFRhYmxlKCdyZXdhcmRzJyk7CiAgICBsZXQgcmVjID0gcmV3YXJkcy5maW5kT25lKHt9KTsKICAgIH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jdXJyZW5jeShhLCB7IHByZWNpc2lvbjogMyB9KS5zdWJ0cmFjdChiKTsKfQoKbGV0IGNvdW50RGVjaW1hbHMgPSBmdW5jdGlvbiAodmFsdWUpIHsKICBpZiAoTWF0aC5mbG9vcih2YWx1ZSkgPT09IHZhbHVlKSByZXR1cm4gMDsKICByZXR1cm4gdmFsdWUudG9TdHJpbmcoKS5zcGxpdCgnLicpWzFdLmxlbmd0aCB8fCAwOwp9"
}
}
}
{
"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": "Y29uc3QgVE9LRU5TWU1CT0wgPSAnU01NS1QnOwphY3Rpb25zLmNyZWF0ZVNTQyA9IGZ1bmN0aW9uIChwYXlsb2FkKSB7CiAgZGIuY3JlYXRlVGFibGUoJ2JhbGFuY2VzJyk7CiAgbGV0IHJld2FyZHMgPSBkYi5jcmVhdGVUYWJsZSgncmV3YXJkcycpOwogIHJld2FyZHMuaW5zZXJ0KHsKICAgICdwZW5kaW5nUmV3YXJkcyc6IDAsCiAgICAncmV3YXJkc0Rpc3RyaWJ1dGlvbkludGVydmFsJzogMzAwMDAsCiAgICAnbGFzdEJsb2NrUmV3YXJkJzogcmVmU3RlZW1CbG9ja051bWJlciwKICAgICd0b2tlbklzc3VhbmNlUmF0ZSc6IDEsCiAgICAnbmV4dEhhbHZpbmcnOiA1MDAwMDAsCiAgICAnYmVuZWZpY2lhcmllcyc6IFsnc21tYXJrZXR0b2tlbiddCiAgfSkKfQoKYWN0aW9ucy51cGRhdGVSZXdhcmRzRGlzdHJpYnV0aW9uSW50ZXJ2YWwgPSBmdW5jdGlvbiAocGF5bG9hZCkgewogIGlmIChzZW5kZXIgIT09IG93bmVyKSByZXR1cm47CgogIGNvb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GN1cnJlbmN5KGEsIHsgcHJlY2lzaW9uOiAzIH0pLmFkZChiKTsKfQoKbGV0IHN1YiA9IGZ1bmN0aW9uIChhLCBiKSB7CiAgLy9sZXQgcmVzID0gKChhICogMTAwMCkgLSAoYiAqIDEwMDApKSAvIDEwMDA7CiAgLy9yZXR1cm4gcmVzID4gMCA/IHJlcy50b0ZpeGVkKDMpIDogMDsKICByZXR1cm4gY3VycmVuY3koYSwgeyBwcmVjaXNpb246IDMgfSkuc3VidHJhY3QoYik7Cn0KCmxldCBjb3VudERlY2ltYWxzID0gZnVuY3Rpb24gKHZhbHVlKSB7CiAgaWYgKE1hdGguZmxvb3IodmFsdWUpID09PSB2YWx1ZSkgcmV0dXJuIDA7CiAgcmV0dXJuIHZhbHVlLnRvU3RyaW5nKCkuc3BsaXQoJy4nKVsxXS5sZW5ndGggfHwgMDsKfQ=="
}
}
}
{
"id": "ssc-00000000000000000002",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "tokens",
"params": "",
"code": "Ly9jb25zdCBhY3Rpb25zID0ge30KLy9jb25zdCBhcGkgPSB7fQoKYWN0aW9ucy5jcmVhdGVTU0MgPSBhc3luYyAocGF5bG9hZCkgPT4gewogIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgndG9rZW5zJywgWydzeW1ib2wnXSk7CiAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCdiYWxhbmNlcycsIFsnYWNjb3VudCddKTsKICBhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoJ2NvbnRyYWN0c0JhbGFuY2VzJywgWydhY2NvdW50J10pOwogIGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgncGFyYW1zJyk7CiAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCdwZW5kaW5nVW5zdGFrZXMnLCBbJ2FjY291bnQnLCAndW5zdGFrZUNvbXBsZXRlVGltZXN0YW1wJ10pOwoKICBjb25zdCBwYXJhbXMgP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GFwaS5hc3NlcnQodG9rZW4gPT09IG51bGwsICdzeW1ib2wgYWxyZWFkeSBleGlzdHMnKSkgewogICAgICAgIGNvbnN0IGZpbmFsVXJsID0gdXJsID09PSB1bmRlZmluZWQgPyAnJyA6IHVybDsKCiAgICAgICAgbGV0IG1ldGFkYXRhID0gewogICAgICAgICAgdXJsOiBmaW5hbFVybCwKICAgICAgICB9OwoKICAgICAgICBtZXRhZGF0YSA9IEpTT04uc3RyaW5naWZ5KG1ldGFkYXRhKTsKCiAgICAgICAgY29uc3QgbmV3VG9rZW4gPSB7CiAgICAgICAgICBpc3N1ZXI6IGFwaS5zZW5kZXIsCiAgICAgICAgICBzeW1ib2wsCiAgICAgICAgICBuYW1lLAogICAgICAgICAgbWV0YWRhdGEsCiAgICAgICAgICBwcmVjaXNpb24sCiAgICAgICAgICBtYXhTdXBwbHksCiAgICAgICAgICBzdXBwbHk6IDAsCiAgICAgICAgICBjaXJjdWxhdGluZ1N1cHBseTogMCwKICAgICAgICB9OwoKICAgICAgICBhd2FpdCBhcGkuZGIuaW5zZXJ0KCd0b2tlbnMnLCBuZXdUb2tlbik7CgogICAgICAgIC8vIGJ1cm4gdGhlIHRva2VuIGNyZWF0aW9uIGZlZXMKICAgICAgICBpZiAoYXBpLkJpZ051bWJlcih0b2tlbkNyZWF0aW9uRmVlKS5ndCgwKSkgewogICAgICAgICAgYXdhaXQgYWN0aW9ucy50cmFuc2Zlcih7CiAgICAgICAgICAgIHRvOiAnbnVsbCcsIHN5bWJvbDogIlNTQyIsIHF1YW50aXR5OiBhcGkuQmlnTnVtYmVyKHRva2VuQ3JlYXRpb25GZWUpLnRvTnVtYmVyKCksIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KfTsKCmNvbnN0IGNyZWF0ZVZUd28gPSBhc3luYyAocGF5bG9hZCkgPT4gewogIGNvbnN0IHsKICAgIG5hbWUsIHN5bWJvbCwgd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50aXR5LCAnYmFsYW5jZXMnKTsKCiAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoZmluYWxUbyA9PT0gJ251bGwnKSB7CiAgICAgICAgICAgICAgdG9rZW4uY2lyY3VsYXRpbmdTdXBwbHkgPSBjYWxjdWxhdGVCYWxhbmNlVk9uZSgKICAgICAgICAgICAgICAgIHRva2VuLmNpcmN1bGF0aW5nU3VwcGx5LCBxdWFudGl0eSwgdG9rZW4ucHJlY2lzaW9uLCBmYWxzZSwKICAgICAgICAgICAgICApOwogICAgICAgICAgICAgIGF3YWl0IGFwaS5kYi51cGRhdGUoJ3Rva2VucycsIHRva2VuKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgYXBpLmVtaXQoJ3RyYW5zZmVyJywgewogICAgICAgICAgICAgIGZyb206IGFwaS5zZW5kZXIsIHRvOiBmaW5hbFRvLCBzeW1ib2wsIHF1YW50aXR5LAogICAgICAgICAgICB9KTsKCiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KCiAgcmV0dXJuIGZhbHNlOwp9OwoKY29uc3QgdHJhbnNmZXJWVHdvID0gYXN5bmMgKHBheWxvYWQpID0+IHsKICBjb25zdCB7CiAgICB0bywgc3ltYm9sLCBxdWFudGl0eSwgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogIH0gPSBwYXlsb2FkOwoKICBpZiAoYXBpLmFzc2VydChpc1NpZ25lZFdpdGhBY3RpdmVLZXkgPT09IHRydWUsICd5b3UgbXVzdCB1c2UgYSBjdXN0b21fanNvbiBzaWduZWQgd2l0aCB5b3VyIGFjdGl2ZSBrZXknKQogICAgJiYgYXBpLmFzc2VydCh0byAmJiB0eXBlb2YgdG8gPT09ICdzdHJpbmcnCiAgICAgICYmIHN5bWJvbCAmJiB0eXBlb2Ygc3ltYm9sID09PSAnc3RyaW5nJwogICAgICAmJiBxdW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zZW5kZXIsIHRva2VuLCBxdWFudGl0eSwgJ2JhbGFuY2VzJykpIHsKICAgICAgICAgICAgY29uc3QgcmVzID0gYXdhaXQgYWRkQmFsYW5jZVZUd28oZmluYWxUbywgdG9rZW4sIHF1YW50aXR5LCAnYmFsYW5jZXMnKTsKCiAgICAgICAgICAgIGlmIChyZXMgPT09IGZhbHNlKSB7CiAgICAgICAgICAgICAgYXdhaXQgYWRkQmFsYW5jZVZUd28oYXBpLnNlbmRlciwgdG9rZW4sIHF1YW50aXR5LCAnYmFsYW5jZXMnKTsKCiAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoZmluYWxUbyA9PT0gJ251bGwnKSB7CiAgICAgICAgICAgICAgdG9rZW4uY2lyY3VsYXRpbmdTdXBwbHkgPSBjYWxjdWxhdGVCYWxhbmNlVlR3bygKICAgICAgICAgICAgICAgIHRva2VuLmNpcmN1bGF0aW5nU3VwcGx5LCBxdWFudGl0eSwgdG9rZW4ucHJlY2lzaW9uLCBmYWxzZSwKICAgICAgICAgICAgICApOwogICAgICAgICAgICAgIGF3YWl0IGFwaS5kYi51cGRhdGUoJ3Rva2VucycsIHRva2VuKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgYXBpLmVtaXQoJ3RyYW5zZmVyJywgewogICAgICAgICAgICAgIGZyb206IGFwaS5zZW5kZXIsIHRvOiBmaW5hbFRvLCBzeW1ib2wsIHF1YW50aXR5LAogICAgICAgICAgICB9KTsKCiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KCiAgcmV0dXJuIGZhbHNlOwp9OwoKYWN0aW9ucy50cmFuc2ZlciA9IGFzeW5jIChwYXlsb2FkKSA9PiB7CiAgaWYgKGFwaS5yZWZTdGVlbUJsb2NrTnVtYmVyIDwgMzA4OTY1MDApIHsKICAgIGF3YWl0IHRyYW5zZmVyVk9uZShwYXlsb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AgICBpZiAoYXBpLmFzc2VydCh0b2tlbiAhPT0gbnVsbCwgJ3N5bWJvbCBkb2VzIG5vdCBleGlzdCcpCiAgICAgICAgICAgICYmIGFwaS5hc3NlcnQoY291bnREZWNpbWFscyhxdWFudGl0eSkgPD0gdG9rZW4ucHJlY2lzaW9uLCAnc3ltYm9sIHByZWNpc2lvbiBtaXNtYXRjaCcpCiAgICAgICAgICAgICYmIGFwaS5hc3NlcnQoYXBpLkJpZ051bWJlcihxdWFudGl0eSkuZ3QoMCksICdtdXN0IHRyYW5zZmVyIHBvc2l0aXZlIHF1YW50aXR5JykpIHsKCiAgICAgICAgICAgIGlmIChhd2FpdCBzdWJCYWxhbmNlVlR3byhmcm9tLCB0b2tlbiwgcXVhbnRpdHksICdjb250cmFjdHNCYWxhbmNlcycpKSB7CiAgICAgICAgICAgICAgY29uc3QgcmVzID0gYXdhaXQgYWRkQmFsYW5jZVZUd28oZmluYWxUbywgdG9rZW4sIHF1YW50aXR5LCB0YWJsZSk7CgogICAgICAgICAgICAgIGlmIChyZXMgPT09IGZhbHNlKSB7CiAgICAgICAgICAgICAgICBhd2FpdCBhZGRCYWxhbmNlVlR3byhmcm9tLCB0b2tlbiwgcXVhbnRpdHksICdjb250cmFjdHNCYWxhbmNlcycpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBpZiAoZmluYWxUbyA9PT0gJ251bGwnKSB7CiAgICAgICAgICAgICAgICAgIHRva2VuLmNpcmN1bGF0aW5nU3VwcGx5ID0gY2FsY3VsYXRlQmFsYW5jZVZUd28oCiAgICAgICAgICAgICAgICAgICAgdG9rZW4uY2lyY3VsYXRpbmdTdXBwbHksIHF1YW50aXR5LCB0b2tlbi5wcmVjaXNpb24sIGZhbHNlLAogICAgICAgICAgICAgICAgICApOwogICAgICAgICAgICAgICAgICBhd2FpdCBhcGkuZGIudXBkYXRlKCd0b2tlbnMnLCB0b2tlbik7CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAg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VyOwogIH0KCiAgY29uc3Qgc2Vjb25kc2FnbyA9IG5vd1RpbWVTZWMgLSBiYWxhbmNlLmxhc3RWb3RlVGltZTsKICBjb25zdCBuYkRheXMxMDBQZXJjZW50UmVnZW5lcmF0aW9uU2VjcyA9IG5iRGF5czEwMFBlcmNlbnRSZWdlbmVyYXRpb24gKiAyNCAqIDYwICogNjA7CiAgY29uc3QgcmVnZW5lcmF0ZWRQb3dlciA9IGFwaS5CaWdOdW1iZXIoMTAwKQogICAgLmRpdmlkZWRCeShuYkRheXMxMDBQZXJjZW50UmVnZW5lcmF0aW9uU2VjcykKICAgIC5tdWx0aXBsaWVkQnkoc2Vjb25kc2FnbykKICAgIC50b0ZpeGVkKDIpOwoKICBjb25zdCBuZXdWb3RpbmdQb3dlciA9IGFwaS5CaWdOdW1iZXIoYmFsYW5jZS52b3RpbmdQb3dlcikKICAgIC5wbHVzKHJlZ2VuZXJhdGVkUG93ZXIpCiAgICAudG9GaXhlZCgyKTsKCiAgcmV0dXJuIGFwaS5CaWdOdW1iZXIobmV3Vm90aW5nUG93ZXIpLmd0KDEwMCkgPyAnMTAwLjAwJyA6IG5ld1ZvdGluZ1Bvd2VyOwp9OwoKY29uc3QgY291bnREZWNpbWFscyA9IHZhbHVlID0+IGFwaS5CaWdOdW1iZXIodmFsdWUpLmRwKCk7Cg=="
}
}
}
{
"id": "ssc-00000000000000000002",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "test",
"params": "",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBhc3luYyAocGF5bG9hZCkgPT4gewogICAgICAgICAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCd0ZXN0VXBkYXRlVGFibGUnKTsKICAgICAgICB9"
}
}
}
{
"id": "ssc-testnet1",
"json": {
"contractName": "contract",
"contractAction": "update",
"contractPayload": {
"name": "tokens",
"params": "",
"code": "YWN0aW9ucy5jcmVhdGVTU0M9KGFzeW5jKCk9PntsZXQgYT1h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kZXIsIm5vdCBhdXRob3JpemVkIikpe2NvbnN0IGE9bmV3IERhdGUoYCR7YXBpLnN0ZWVtQmxvY2tUaW1lc3RhbXB9LjAwMFpgKS5nZXRUaW1lKCk7bGV0IGU9YXdhaXQgYXBpLmRiLmZpbmQoInBlbmRpbmdVbmRlbGVnYXRpb25zIix7Y29tcGxldGVUaW1lc3RhbXA6eyRsdGU6YX19KSx0PWUubGVuZ3RoO2Zvcig7dD4wOyl7Zm9yKGxldCBhPTA7YTx0O2ErPTEpe2NvbnN0IHQ9ZVthXTthd2FpdCBwcm9jZXNzVW5kZWxlZ2F0aW9uKHQpfXQ9KGU9YXdhaXQgYXBpLmRiLmZpbmQoInBlbmRpbmdVbmRlbGVnYXRpb25zIix7Y29tcGxldGVUaW1lc3RhbXA6eyRsdGU6YX19KSkubGVuZ3RofX19KTs="
}
}
}
{
"id": "ssc-00000000000000000002",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "test",
"params": "",
"code": "YWN0aW9ucy5jcmVhdGVTU0MgPSBhc3luYyAocGF5bG9hZCkgPT4gewogICAgICAgICAgYXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCd0ZXN0VXBkYXRlVGFibGUnKTsKICAgICAgICB9"
}
}
}
{
"id": "ssc-testnet1",
"json": {
"contractName": "contract",
"contractAction": "update",
"contractPayload": {
"name": "witnesses",
"params": "",
"code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBnbG9iYWwgYWN0aW9ucywgYXBpICovCgpjb25zdCBOQl9BUFBST1ZBTFNfQUxMT1dFRCA9IDMwOwpjb25zdCBOQl9UT1BfV0lUTkVTU0VTID0gNDsKY29uc3QgTkJfQkFDS1VQX1dJVE5FU1NFUyA9IDE7CmNvbnN0IE5CX1dJVE5FU1NFUyA9IE5CX1RPUF9XSVRORVNTRVMgKyBOQl9CQUNLVVBfV0lUTkVTU0VTOwpjb25zdCBOQl9XSVRORVNTRV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B3ZWlnaHRzOgogICAgICAgICAgYWNjdCBBIDogMTAwMCAoZnJvbSAwIHRvIDEwMDApCiAgICAgICAgICBhY2N0IEIgOiA5MDAgKGZyb20gMTAwMC4wMDAwMDAwMSB0byAxOTAwKQogICAgICAgICAgYWNjdCBDIDogODAwIChmcm9tIDE5MDAuMDAwMDAwMDEgdG8gMjcwMCkKICAgICAgICAgIGFjY3QgRCA6IDcwMCAoZnJvbSAyNzAwLjAwMDAwMDAxIHRvIDM0MDApCiAgICAgICAgICAuLi4KICAgICAgICAgIGFjY3QgbiA6IGZyb20gKChuLTEpLnVwcGVyQm91bmQgKyAwLjAwMDAwMDAxKSB0byAxMCwwMDApCgogICAgICAgICAgLT4gdG90YWwgYXBwcm92YWwgd2VpZ2h0IHRvcCB3aXRuZXNzZXMgKEEtRCkgPSAzLDQwMAogICAgICAgICAgLT4gcGljayB1cCBiYWNrdXAgd2l0bmVzc2VzIChFLW4pOiB3ZWlnaHQgcmFuZ2U6CiAgICAgICAgICAgIGZyb20gMyw0MDAuMDAwMDAwMSB0byAxMCwwMDAKICAgICAgKi8KCiAgICAgIC8vIGdldCBhIGRldGVybWluaXN0aWMgcmFuZG9tIHdlaWdodAogICAgICBjb25zdCByYW5kb20gPSBhcGkucmFuZG9tKCk7CiAgICAgIGxldCByYW5kb21XZWlnaHQgPSBudWxsOwoKICAgICAgbGV0IG9mZnNldCA9IDA7CiAgICAgIGxldCBhY2NXZWlnaHQgPSAwOwoKICAgICAgbGV0IHdpdG5lc3NlcyA9IGF3YWl0IGFwaS5kYi5maW5kKAogICAgICAgICd3aXRuZXNzZXMnLAogICAgICAgIHsKICAgICAgICAgIGFwcHJvdmFsV2VpZ2h0OiB7CiAgICAgICAgICAgICRndDogewogICAgICAgICAgICAgICRudW1iZXJEZWNpbWFsOiAnMCcsCiAgICAgICAgICAgIH0sCiAgICAgICAgICB9LAogICAgICAgIH0sCiAgICAgICAgMTAwLCAvLyBsaW1pdAogICAgICAgIG9mZnNldCwgLy8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ZXNzIGlzIGVuYWJsZWQKICAgICAgICAgIGlmICh3aXRuZXNzLmVuYWJsZWQgPT09IHRydWUpIHsKICAgICAgICAgICAgLy8gaWYgd2UgaGF2ZW4ndCBmb3VuZCBhbGwgdGhlIHRvcCB3aXRuZXNzZXMgeWV0CiAgICAgICAgICAgIGlmIChzY2hlZHVsZS5sZW5ndGggPCBOQl9UT1BfV0lUTkVTU0VTCiAgICAgICAgICAgICAgfHwgYXBpLkJpZ051bWJlcihyYW5kb21XZWlnaHQpLmx0ZShhY2NXZWlnaHQpKSB7CiAgICAgICAgICAgICAgc2NoZWR1bGUucHVzaCh7CiAgICAgICAgICAgICAgICB3aXRuZXNzOiB3aXRuZXNzLmFjY291bnQsCiAgICAgICAgICAgICAgICBibG9ja051bWJlcjogbnVsbCwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQoKICAgICAgICAgIGlmIChzY2hlZHVsZS5sZW5ndGggPj0gTkJfV0lUTkVTU0VTKSB7CiAgICAgICAgICAgIGluZGV4ID0gd2l0bmVzc2VzLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGlmIChzY2hlZHVsZS5sZW5ndGggPCBOQl9XSVRORVNTRVMpIHsKICAgICAgICAgIG9mZnNldCArPSAxMDA7CiAgICAgICAgICB3aXRuZXNzZXMgPSBhd2FpdCBhcGkuZGIuZmluZCgKICAgICAgICAgICAgJ3dpdG5lc3NlcycsCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICBhcHByb3ZhbFdlaWdodDogewogICAgICAgICAgICAgICAgJGd0OiB7CiAgICAgICAgICAgICAgICAgICRudW1iZXJEZWNpbWFsOiAnMCcsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgIH0sCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIDEwMCwgLy8gbGltaXQKICAgICAgICAgICAgb2Zmc2V0LCAvLyBvZmZzZXQKICAgICAgICAgICAgWwogICAgICAgICAgICAgIH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KICAgICAgICBjb25zdCBjdXJyZW50V2l0bmVzc0luZm8gPSBhd2FpdCBhcGkuZGIuZmluZE9uZSgnd2l0bmVzc2VzJywgeyBhY2NvdW50OiBjdXJyZW50V2l0bmVzcyB9KTsKICAgICAgICBjb25zdCBjdXJyZW50V2l0bmVzc1NpZ25hdHVyZSA9IHNpZ25hdHVyZXMuZmluZChzID0+IHNbMF0gPT09IGN1cnJlbnRXaXRuZXNzKTsKICAgICAgICBmb3IgKGxldCBpbmRleCA9IDA7IGluZGV4IDwgc2NoZWR1bGVzLmxlbmd0aDsgaW5kZXggKz0gMSkgewogICAgICAgICAgY29uc3Qgc2NoZWR1bGVkV2l0bmVzcyA9IHNjaGVkdWxlc1tpbmRleF07CiAgICAgICAgICBjb25zdCB3aXRuZXNzID0gYXdhaXQgYXBpLmRiLmZpbmRPbmUoJ3dpdG5lc3NlcycsIHsgYWNjb3VudDogc2NoZWR1bGVkV2l0bmVzcy53aXRuZXNzIH0pOwogICAgICAgICAgaWYgKHdpdG5lc3MgIT09IG51bGwpIHsKICAgICAgICAgICAgY29uc3Qgc2lnbmF0dXJlID0gc2lnbmF0dXJlcy5maW5kKHMgPT4gc1swXSA9PT0gd2l0bmVzcy5hY2NvdW50KTsKICAgICAgICAgICAgaWYgKHNpZ25hdHVyZSkgewogICAgICAgICAgICAgIGlmIChhcGkuY2hlY2tTaWduYXR1cmUoCiAgICAgICAgICAgICAgICBjYWxjdWxhdGVkUm91bmRIYXNoLCBzaWduYXR1cmVbMV0sIHdpdG5lc3Muc2lnbmluZ0tleSwgdHJ1ZSwKICAgICAgICAgICAgICApKSB7CiAgICAgICAgICAgICAgICBhcGkuZGVidWcoYHdpdG5lc3MgJHt3aXRuZXNzLmFjY291bnR9IHNpZ25lZCByb3VuZCAke3JvdW5kfWApOwogICAgICAgICAgICAgICAgc2lnbmF0dXJlc0NoZWNrZWQgKz0gMTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIC8vIHRoZSBjdXJyZW50IHdpdG5lc3Mgd2lsbCBzaG93IGFzIHRoZSB3aXRuZXNzIHRoYXQgdmVyaWZpZWQgdGhlIGJsb2NrcyBmcm9tIHRoZSByb3VuZAogICAgICAgICAgICB2ZXJpZmllZEJsb2NrSW5mb3JtYXRpb24ucHVzaCgKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBibG9ja051bWJlcjogc2NoZWR1bGVkV2l0bmVzcy5ibG9ja051bWJlciwKICAgICAgICAgICAgICAgIHdpdG5lc3M6IGN1cnJlbnRXaXRuZXNzLAogICAgICAgICAgICAgICAgc2lnbmluZ0tleTogY3VycmVudFdpdG5lc3NJbmZvLnNpZ25pbmdLZXksCiAgICAgICAgICAgICAgICByb3VuZFNpZ25hdHVyZTogY3VycmVudFdpdG5lc3NTaWduYXR1cmVbMV0sCiAgICAgICAgICAgICAgICByb3VuZCwKICAgICAgICAgICAgICAgIHJvdW5kSGFzaCwKICAgICAgICAgICAgICB9LAogICAgICAgICAgICApOwogICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaWYgKHNpZ25hdHVyZXNDaGVja2VkID49IE5CX1dJVE5FU1NFU19TSUdOQVRVUkVTX1JFUVVJUkVEKSB7CiAgICAgICAgICAvLyBtYXJrIGJsb2NrcyBvZiB0aGUgdmVyaWZpZWQgcm91bmQgYXMgdmVyaWZpZWQgYnkgdGhlIGN1cnJlbnQgd2l0bmVzcwogICAgICAgICAgZm9yIChsZXQgaW5kZXggPSAwOyBpbmRleCA8IHZlcmlmaWVkQmxvY2tJbmZvcm1hdGlvbi5sZW5ndGg7IGluZGV4ICs9IDEpIHsKICAgICAgICAgICAgYXdhaXQgYXBpLnZlcmlmeUJsb2NrKHZlcmlmaWVkQmxvY2tJbmZvcm1hdGlvbltpbmRleF0pOwogICAgICAgICAgfQoKICAgICAgICAgIC8vIGdldCBjb250cmFjdCBiYWxhbmNlCiAgICAgICAgICBjb25zdCBjb250cmFjdEJhbGFuY2UgPSBhd2FpdC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IHBhcmFtcy5jdXJyZW50V2l0bmVzcyA9IG51bGw7CiAgICAgICAgICBwYXJhbXMubGFzdFZlcmlmaWVkQmxvY2tOdW1iZXIgPSBsYXN0QmxvY2tSb3VuZDsKICAgICAgICAgIGF3YWl0IGFwaS5kYi51cGRhdGUoJ3BhcmFtcycsIHBhcmFtcyk7CgogICAgICAgICAgLy8gdXBkYXRlIGluZm9ybWF0aW9uIGZvciB0aGUgY3VycmVudCB3aXRuZXNzCiAgICAgICAgICBjb25zdCB3aXRuZXNzID0gYXdhaXQgYXBpLmRiLmZpbmRPbmUoJ3dpdG5lc3NlcycsIHsgYWNjb3VudDogY3VycmVudFdpdG5lc3MgfSk7CiAgICAgICAgICB3aXRuZXNzLm1pc3NlZFJvdW5kc0luQVJvdyA9IDA7CiAgICAgICAgICB3aXRuZXNzLmxhc3RSb3VuZFZlcmlmaWVkID0gcm91bmQ7CiAgICAgICAgICB3aXRuZXNzLmxhc3RCbG9ja1ZlcmlmaWVkID0gbGFzdEJsb2NrUm91bmQ7CiAgICAgICAgICB3aXRuZXNzLnZlcmlmaWVkUm91bmRzICs9IDE7CiAgICAgICAgICBhd2FpdCBhcGkuZGIudXBkYXRlKCd3aXRuZXNzZXMnLCB3aXRuZXNzKTsKCiAgICAgICAgICAvLyBjYWxjdWxhdGUgbmV3IHNjaGVkdWxlCiAgICAgICAgICBhd2FpdCBtYW5hZ2VXaXRuZXNzZXNTY2hlZHVsZSgpOwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KfTsKCmFjdGlvbnMuc2NoZWR1bGVXaXRuZXNzZXMgPSBhc3luYyAoKSA9PiB7CiAgaWYgKGFwaS5zZW5kZXIgIT09ICdudWxsJykgcmV0dXJuOwoKICBhd2FpdCBtYW5hZ2VXaXRuZXNzZXNTY2hlZHVsZSgpOwp9Owo="
}
}
}
{
"id": "ssc-testnet1",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "inflation",
"params": "",
"code": "LyogZXNsaW50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gIndpdG5lc3NlcyIgY29udHJhY3QKICAvLyAyMDBrIHRva2VucyBwZXIgeWVhciA9IDIyLjgzMTA1MDIyIHRva2VucyBwZXIgaG91ciAoYW4gaG91ciA9IDEyMDAgYmxvY2tzKQogIG5iVG9rZW5zID0gJzIyLjgzMTA1MDIyJzsKICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ3Rva2VucycsICdpc3N1ZVRvQ29udHJhY3QnLCB7IHN5bWJvbDogVVRJTElUWV9UT0tFTl9TWU1CT0wsIHF1YW50aXR5OiBuYlRva2VucywgdG86ICd3aXRuZXNzZXMnIH0pOwp9Owo="
}
}
}
{
"id": "ssc-testnet1",
"json": {
"contractName": "contract",
"contractAction": "update",
"contractPayload": {
"name": "nft",
"params": "",
"code": "Y29uc3QgQ09OVFJBQ1RfTkFNRT0ibmZ0IixVVElMSVRZX1RPS0VOX1NZTUJPTD0iU1NDIixNQVhfTlVNX0FVVEhPUklaRURfSVNTVUVSUz0xMCxNQVhfTlVNX0xPQ0tFRF9UT0tFTl9UWVBFUz0xMCxNQVhfU1lNQk9MX0xFTkdUSD0xMCxNQVhfREFUQV9QUk9QRVJUWV9MRU5HVEg9MTAwLE1BWF9OVU1fTkZUU19JU1NVQUJMRT0xMCxNQVhfTlVNX05GVFNfRURJVEFCTEU9NTAsTUFYX05VTV9ORlRTX09QRVJBQkxFPTUwO2FjdGlvbnMuY3JlYXRlU1NDPShhc3luYygpPT57aWYoITE9PT1hd2FpdCBhcGkuZGIudGFibGVFeGlzdHMoIm5mdHMiKSl7YXdhaXQgYXBpLmRiLmNyZWF0ZVRhYmxlKCJuZnRzIixbInN5bWJvbCJdKSxhd2FpdCBhcGkuZGIuY3JlYXRlVGFibGUoInBhcmFtcyIpLGF3YWl0IGFwaS5kYi5jcmVhdGVUYWJsZSgicGVuZGluZ1VuZGVsZWdhdGlvbnMiLFsic3ltYm9sIiwiY29tcGxldGVUaW1lc3RhbXAiXSk7Y29uc3QgZT17b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IpJiZhcGkuYXNzZXJ0KHQmJiJvYmplY3QiPT10eXBlb2YgdCYmQXJyYXkuaXNBcnJheSh0KSwiaW52YWxpZCBwYXJhbXMiKSYmYXBpLmFzc2VydCh0Lmxlbmd0aDw9MTAsImNhbm5vdCBpc3N1ZSBtb3JlIHRoYW4gMTAgTkZUIGluc3RhbmNlcyBhdCBvbmNlIikpZm9yKGxldCBlPTA7ZTx0Lmxlbmd0aDtlKz0xKXtjb25zdHtzeW1ib2w6cyxmcm9tVHlwZTpuLHRvOnIsdG9UeXBlOm8sZmVlU3ltYm9sOnAsbG9ja1Rva2VuczpjLHByb3BlcnRpZXM6ZH09dFtlXTthd2FpdCBhY3Rpb25zLmlzc3VlKHtzeW1ib2w6cyxmcm9tVHlwZTpuLHRvOnIsdG9UeXBlOm8sZmVlU3ltYm9sOnAsbG9ja1Rva2VuczpjLHByb3BlcnRpZXM6ZCxpc1NpZ25lZFdpdGhBY3RpdmVLZXk6YSxjYWxsaW5nQ29udHJhY3RJbmZvOml9KX19KTs="
}
}
}
{
"id": "ssc-testnet1",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "crittermanager",
"params": "",
"code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBlc2xpbnQtZGlzYWJsZSBtYXgtbGVuICovCi8qIGdsb2JhbCBhY3Rpb25zLCBhcGkgKi8KCi8vIHRlc3QgY29udHJhY3QgdG8gZGVtb25zdHJhdGUgU3BsaW50ZXJsYW5kcyBzdHlsZQovLyBwYWNrIGlzc3VhbmNlIG9mIGNvbGxlY3RhYmxlIGNyaXR0ZXJzCmNvbnN0IENPTlRSQUNUX05BTUUgPSAnY3JpdHRlcm1hbmFnZXInOwoKLy8gbm9ybWFsbHkgd2Ugd291bGQgdXNlIGFwaS5vd25lciB0byByZWZlciB0byB0aGUgY29udHJhY3QKLy8gb3duZXIgKHRoZSBhY2NvdW50IHRoYXQgZGVwbG95ZWQgdGhlI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waS5zZW5kZXIpKTsKICAgICAgICAgIH0KCiAgICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICdpc3N1ZU11bHRpcGxlJywgewogICAgICAgICAgICBpbnN0YW5jZXMsCiAgICAgICAgICAgIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfQogICAgfQogIH0KICByZXR1cm4gZmFsc2U7Cn07Cg=="
}
}
}
{
"id": "ssc-testnet1",
"json": {
"contractName": "contract",
"contractAction": "deploy",
"contractPayload": {
"name": "nftmarket",
"params": "",
"code": "LyogZXNsaW50LWRpc2FibGUgbm8tYXdhaXQtaW4tbG9vcCAqLwovKiBlc2xpbnQtZGlzYWJsZSBtYXgtbGVuICovCi8qIGVzbGludC1kaXNhYmxlIHByZWZlci10ZW1wbGF0ZSAqLwovKiBlc2xpbnQtZGlzYWJsZSBuby11bmRlcnNjb3JlLWRhbmdsZSAqLwovKiBnbG9iYWwgYWN0aW9ucywgYXBpICovCgpjb25zdCBDT05UUkFDVF9OQU1FID0gJ25mdG1hcmtldCc7CgovLyBjYW5ub3QgYnV5IG9yIHNlbGwgbW9yZSB0aGFuIHRoaXMgbnVtYmVyIG9mIE5GVCBpbnN0YW5jZXMgaW4gb25lIGFjdGlvbgpjb25zdCBNQVhfTlVNX1VOSVRTX09QRVJBQkxFID0gNTA7CgphY3Rpb25zLmNyZWF0ZVNTQyA9IGFzeW5jICgpID0+IHsKICAvLyBub3RoaW5nIHRvIGRvIGhlcmUKfTsKCi8vIGNoZWNrIHRoYXQgdG9rZW4gdHJhbnNmZXJzIHN1Y2NlZWRlZApjb25zdCBpc1Rva2VuVHJhbnNmZXJWZXJpZmllZCA9IChyZXN1bHQsIGZyb20sIHRvLCBzeW1ib2wsIHF1YW50aXR5LCBldmVudFN0cikgPT4gewogIGlmIChyZXN1bHQuZXJyb3JzID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eyBzeW1ib2w6IHByaWNlU3ltYm9sIH0pOwogICAgICBpZiAoYXBpLmFzc2VydCh0b2tlbgogICAgICAgICYmIGFwaS5CaWdOdW1iZXIocHJpY2UpLmd0KDApCiAgICAgICAgJiYgY291bnREZWNpbWFscyhwcmljZSkgPD0gdG9rZW4ucHJlY2lzaW9uLCAnaW52YWxpZCBwcmljZScpKSB7CiAgICAgICAgY29uc3QgZmluYWxQcmljZSA9IGFwaS5CaWdOdW1iZXIocHJpY2UpLnRvRml4ZWQodG9rZW4ucHJlY2lzaW9uKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG9yZGVycy5sZW5ndGg7IGkgKz0gMSkgewogICAgICAgICAgY29uc3Qgb3JkZXIgPSBvcmRlcnNbaV07CiAgICAgICAgICBjb25zdCBvbGRQcmljZSA9IG9yZGVyLnByaWNlOwogICAgICAgICAgb3JkZXIucHJpY2UgPSBmaW5hbFByaWNlOwogICAgICAgICAgb3JkZXIucHJpY2VEZWMgPSB7ICRudW1iZXJEZWNpbWFsOiBmaW5hbFByaWNlIH07CgogICAgICAgICAgYXdhaXQgYXBpLmRiLnVwZGF0ZShtYXJrZXRUYWJsZU5hbWUsIG9yZGVyKTsKCiAgICAgICAgICBhcGkuZW1pdCgnY2hhbmdlUHJpY2UnLCB7CiAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgbmZ0SWQ6IG9yZGVyLm5mdElkLAogICAgICAgICAgICBvbGRQcmljZSwKICAgICAgICAgICAgbmV3UHJpY2U6IG9yZGVyLnByaWNlLAogICAgICAgICAgICBwcmljZVN5bWJvbDogb3JkZXIucHJpY2VTeW1ib2wsCiAgICAgICAgICAgIG9yZGVySWQ6IG9yZGVyLl9pZCwKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KfTsKCmFjdGlvbnMuY2FuY2VsID0gYXN5bmMgKHBheWxvYWQpID0+IHsKICBjb25zdCB7CiAgICBzeW1ib2wsCiAgICBuZnRzL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AgICAmJiBldi5kYXRhLmZyb21UeXBlID09PSAnYycKICAgICAgICAgICAgJiYgZXYuZGF0YS50byA9PT0gYXBpLnNlbmRlcgogICAgICAgICAgICAmJiBldi5kYXRhLnRvVHlwZSA9PT0gJ3UnCiAgICAgICAgICAgICYmIGV2LmRhdGEuc3ltYm9sID09PSBzeW1ib2wpIHsKICAgICAgICAgICAgLy8gdHJhbnNmZXIgaXMgdmVyaWZpZWQsIG5vdyB3ZSBjYW4gY2FuY2VsIHRoZSBvcmRlcgogICAgICAgICAgICBjb25zdCBpbnN0YW5jZUlkID0gZXYuZGF0YS5pZDsKICAgICAgICAgICAgaWYgKGluc3RhbmNlSWQgaW4gaWRNYXApIHsKICAgICAgICAgICAgICBjb25zdCBvcmRlciA9IGlkTWFwW2luc3RhbmNlSWRdOwoKICAgICAgICAgICAgICBhd2FpdCBhcGkuZGIucmVtb3ZlKG1hcmtldFRhYmxlTmFtZSwgb3JkZXIpOwoKICAgICAgICAgICAgICBhcGkuZW1pdCgnY2FuY2VsT3JkZXInLCB7CiAgICAgICAgICAgICAgICBhY2NvdW50OiBvcmRlci5hY2NvdW50LAogICAgICAgICAgICAgICAgb3duZWRCeTogb3JkZXIub3duZWRCeSwKICAgICAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgICAgIG5mdElkOiBvcmRlci5uZnRJZCwKICAgICAgICAgICAgICAgIHRpbWVzdGFtcDogb3JkZXIudGltZXN0YW1wLAogICAgICAgICAgICAgICAgcHJpY2U6IG9yZGVyLnByaWNlLAogICAgICAgICAgICAgICAgcHJpY2VTeW1ib2w6IG9yZGVyLnByaWNlU3ltYm9sLAogICAgICAgICAgICAgICAgZmVlOiBvcmRlci5mZWUsCiAgICAgICAgICAgICAgICBvcmRlcklkOiBvcmRlci5faWQsCiAgICAgICAgICAgICAgfSk7CgogICAgICAgICAgICAgIGNvbnN0IGtleSA9IG1ha2VHcm91cGluZ0tleShvcmRlci5ncm91cGluZywgbmZ0Lmdyb3VwQnkpOwogICAgICAgICAgICAgIGNvbnN0IGdyb3VwSW5mbyA9IGtleSBpbiBncm91cGluZ01hcAogICAgICAgICAgICAgICAgPyBncm91cGluZ01hcFtrZXldCiAgICAgICAgICAgICAgICA6IHsKICAgICAgICAgICAgICAgICAgZ3JvdXBpbmc6IG9yZGVyLmdyb3VwaW5nLAogICAgICAgICAgICAgICAgICBpc0luQ29sbGVjdGlvbjogZmFsc2UsCiAgICAgICAgICAgICAgICAgIGNvdW50OiAwLAogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICBncm91cEluZm8uY291bnQgLT0gMTsKICAgICAgICAgICAgICBncm91cGluZ01hcFtrZXldID0gZ3JvdXBJbmZvOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyB1cGRhdGUgb3BlbiBpbnRlcmVzdCBtZXRyaWNzCiAgICAgICAgYXdhaXQgdXBkYXRlT3BlbkludGVyZXN0KCdzZWxsJywgc3ltYm9sLCBwcmljZVN5bWJvbCwgZ3JvdXBpbmdNYXAsIG5mdC5ncm91cEJ5KTsKICAgICAgfQogICAgfQogIH0KfTsKCmFjdGlvbnMuYnV5ID0gYXN5bmMgKHBheWxvYWQpID0+IHsKICBjb25zdCB7CiAgICBzeW1ib2wsCiAgICBuZnRzLAogICAgbWFya2V0QWNjb3VudCwKICAgIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICB9ID0gcGF5bG9hZDsKCiAgaWYgKCFhcGkuYXNzZXJ0KHN5bWJvbCAmJiB0eXBlb2Ygc3ltYm9sID09PSAnc3RyaW5nJwogICAgJiYgbWFya2V0QWNjb3VudCAmJiB0eXBlb2YgbWFya2V0QWNjb3VudCA9PT0gJ3N0cmluZycsICdpbnZhbGlkIHBhcmFtcycpKSB7CiAgICByZXR1cm47CiAgfQoKICBjb25zdCBtYXJrZXRUYWJsZU5hbWUgPSBzeW1ib2wgKyAnc2VsbEJvb2snOwogIGNvbnN0IHRhYmxlRXhpc3RzID0g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sgaW5kZXg6ICduZnRJZCcsIGRlc2NlbmRpbmc6IGZhbHNlIH1dLAogICAgICApOwoKICAgICAgaWYgKG9yZGVycy5sZW5ndGggPiAwKSB7CiAgICAgICAgLy8gZG8gYSBjb3VwbGUgbW9yZSBzYW5pdHkgY2hlY2tzCiAgICAgICAgbGV0IHByaWNlU3ltYm9sID0gJyc7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBvcmRlcnMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICAgIGNvbnN0IG9yZGVyID0gb3JkZXJzW2ldOwogICAgICAgICAgaWYgKHByaWNlU3ltYm9sID09PSAnJykgewogICAgICAgICAgICAoeyBwcmljZVN5bWJvbCB9ID0gb3JkZXIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKCFhcGkuYXNzZXJ0KCEob3JkZXIub3duZWRCeSA9PT0gJ3UnICYmIG9yZGVyLmFjY291bnQgPT09IGFwaS5zZW5kZXIpLCAnY2Fubm90IGZpbGwgeW91ciBvd24gb3JkZXJzJykKICAgICAgICAgICAgfHwgIWFwaS5hc3NlcnQocHJpY2VTeW1ib2wgPT09IG9yZGVyLnByaWNlU3ltYm9sLCAnYWxsIG9yZGVycyBtdXN0IGhhdmUgdGhlIHNhbWUgcHJpY2Ugc3ltYm9sJykpIHsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvLyBnZXQgdGhlIHByaWNlIHRva2VuIHBhcmFtcwogICAgICAgIGNvbnN0IHRva2VuID0gYXdhaXQgYXBpLmRiLmZpbmRPbmVJblRhYmxlKCd0b2tlbnMnLCAndG9rZW5zJywgeyBzeW1ib2w6IHByaWNlU3ltYm9sIH0pOwogICAgICAgIGlmICghdG9rZW4pIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIC8vIGNyZWF0ZSBvcmRlciBtYXBzCiAgICAgICAgbGV0IGZlZVRvdGFsID0gYXBpLkJpZ051bWJlcigwKTsKICAgICAgICBsZXQgcGF5bWVudFRvdGFsID0gYXBpLkJpZ051bWJlcigwKTsKICAgICAgICBsZXQgc29sZE5mdHMgPSBbXTsKICAgICAgICBjb25zdCBzZWxsZXJzID0gW107CiAgICAgICAgY29uc3Qgc2VsbGVyTWFwID0ge307CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBvcmRlcnMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICAgIGNvbnN0IG9yZGVyID0gb3JkZXJzW2ldOwogICAgICAgICAgY29uc3QgZmluYWxQcmljZSA9IGFwaS5CaWdOdW1iZXIob3JkZXIucHJpY2UpOwogICAgICAgICAgY29uc3QgZmVlUGVyY2VudCA9IG9yZGVyLmZlZSAvIDEwMDAwOwogICAgICAgICAgbGV0IGZpbmFsRmVlID0gZmluYWxQcmljZS5tdWx0aXBsaWVkQnkoZmVlUGVyY2VudCkuZGVjaW1hbFBsYWNlcyh0b2tlbi5wcmVjaXNpb24pOwogICAgICAgICAgaWYgKGZpbmFsRmVlLmd0KGZpbmFsUHJpY2UpKSB7CiAgICAgICAgICAgIGZpbmFsRmVlID0gZmluYWxQcmljZTsgLy8gdW5saWtlbHkgYnV0IG5lZWQgdG8gYmUgc3VyZQogICAgICAgICAgfQogICAgICAgICAgbGV0IGZpbmFsUGF5bWVudCA9IGZpbmFsUHJpY2UubWludXMoZmluYWxGZWUpLmRlY2ltYWxQbGFjZXModG9rZW4ucHJlY2lzaW9uKTsKICAgICAgICAgIGlmIChmaW5hbFBheW1lbnQubHQoMCkpIHsKICAgICAgICAgICAgZmluYWxQYXltZW50ID0gYXBpLkJpZ051bWJlcigwKTsgLy8gdW5saWtlbHkgYnV0IG5lZWQgdG8gYmUgc3VyZQogICAgICAgICAgfQogICAgICAgICAgcGF5bWVudFRvdGFsID0gcGF5bWVudFRvdGFsLnBsdXMoZmluYWxQYXltZW50KTsKICAgICAgICAgIGZlZVRvdGFsID0gZmVlVG90YWwucGx1cyhmaW5hbEZlZSk7CgogICAgICAgICAgY29uc3Qga2V5ID0gbWFrZU1hcEtleShvcmRlci5hY2NvdW50LCBvcmRlci5vd25lZEJ5KTsKICAgICAgICAgIGNvbnN0IHNlbGxlckluZm8gPSBrZXkgaW4gc2VsbGVyTWFwCiAgICAgICAgICAgID8gc2VsbGVyTWFwW2tleV0KICAgICAgICAgICAgOiB7CiAgICAgICAgICAgICAgYWNjb3VudDogb3JkZXIuYWNjb3VudCwKICAgICAgICAgICAgICBvd25lZEJ5OiBvcmRlci5vd25lZEJ5LAogICAgICAgICAgICAgIG5mdElkczogW10sCiAgICAgICAgICAgICAgcGF5bWVudFRvdGFsOiBhcGkuQmlnTnVtYmVyKDApLAogICAgICAgICAgICB9OwoKICAgICAgICAgIHNlbGxlckluZm8ucGF5bWVudFRvdGFsID0gc2VsbGVySW5mby5wYXltZW50VG90YWwucGx1cyhmaW5hbFBheW1lbnQpOwogICAgICAgICAgc2VsbGVySW5mby5uZnRJZHMucHVzaChvcmRlci5uZnRJZCk7CiAgICAgICAgICBzZWxsZXJNYXBba2V5XSA9IHNlbGxlckluZm87CiAgICAgICAgfQoKICAgICAgICAvLyB2ZXJpZnkgYnV5ZXIgaGFzIGVub3VnaCBmdW5kcyBmb3IgcGF5bWVudAogICAgICAgIGNvbnN0IHJlcXVpcmVkQmFsYW5jZSA9IHBheW1lbnRUb3RhbC5wbHVzKGZlZVRvdGFsKS50b0ZpeGVkKHRva2VuLnByZWNpc2lvbik7CiAgICAgICAgY29uc3QgYnV5ZXJCYWxhbmNlID0gYXdhaXQgYXBpLmRiLmZpbmRPbmVJblRhYmxlKCd0b2tlbnMnLCAnYmFsYW5jZXMnLCB7IGFjY291bnQ6IGFwaS5zZW5kZXIsIHN5bWJvbDogcHJpY2VTeW1ib2wgfSk7CiAgICAgICAgaWYgKCFhcGkuYXNzZXJ0KGJ1eWVyQmFsYW5jZQogICAgICAgICAgJiYgYXBpLkJpZ051bWJlcihidXllckJhbGFuY2UuYmFsYW5jZSkuZ3RlKHJlcXVpcmVkQmFsYW5jZSksICd5b3UgbXVzdCBoYXZlIGVub3VnaCB0b2tlbnMgZm9yIHBheW1lbnQnKSkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBwYXltZW50VG90YWwgPSBwYXltZW50VG90YWwudG9GaXhlZCh0b2tlbi5wcmVjaXNpb24pOwoKICAgICAgICAvLyBzZW5kIGZlZXMgdG8gbWFya2V0IGFjY291bnQKICAgICAgICBpZiAoZmVlVG90YWwuZ3QoMCkpIHsKICAgICAgICAgIGZlZVRvdGFsID0gZmVlVG90YWwudG9GaXhlZCh0b2tlbi5wcmVjaXNpb24pOwogICAgICAgICAgY29uc3QgcmVzID0gYXdhaXQgYXBpLmV4ZWN1dGVTbWFydENvbnRyYWN0KCd0b2tlbnMnLCAndHJhbnNmZXInLCB7CiAgICAgICAgICAgIHRvOiBmaW5hbE1hcmtldEFjY291bnQsIHN5bWJvbDogcHJpY2VTeW1ib2wsIHF1YW50aXR5OiBmZWVUb3RhbCwgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgICAgfSk7CiAgICAgICAgICBpZiAoIWFwaS5hc3NlcnQoaXNUb2tlblRyYW5zZmVyVmVyaWZpZWQocmVzLCBhcGkuc2VuZGVyLCBmaW5hbE1hcmtldEFjY291bnQsIHByaWNlU3ltYm9sLCBmZWVUb3RhbCwgJ3RyYW5zZmVyJyksICd1bmFibGUgdG8gdHJhbnNmZXIgbWFya2V0IGZlZXMnKSkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyBzZW5kIHBheW1lbnRzIHRvIHNlbGxlcnMKICAgICAgICAvLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgbm8tcmVzdHJpY3RlZC1zeW50YXgKICAgICAgICBmb3IgKGNvbnN0IGluZm8gb2YgT2JqZWN0LnZhbHVlcyhzZWxsZXJNYXApKSB7CiAgICAgICAgICBpZiAoaW5mby5wYXltZW50VG90YWwuZ3QoMCkpIHsKICAgICAgICAgICAgY29uc3QgY29udHJhY3RBY3Rpb24gPSBpbmZvLm93bmVkQnkgPT09ICd1JyA/ICd0cmFuc2ZlcicgOiAndHJhbnNmZXJUb0NvbnRyYWN0JzsKICAgICAgICAgICAgaW5mby5wYXltZW50VG90YWwgPSBpbmZvLnBheW1lbnRUb3RhbC50b0ZpeGVkKHRva2VuLnByZWNpc2lvbik7CiAgICAgICAgICAgIGNvbnN0IHJlcyA9IGF3YWl0IGFwaS5leGVjdXRlU21hcnRDb250cmFjdCgndG9rZW5zJywgY29udHJhY3RBY3Rpb24sIHsKICAgICAgICAgICAgICB0bzogaW5mby5hY2NvdW50LCBzeW1ib2w6IHByaWNlU3ltYm9sLCBxdWFudGl0eTogaW5mby5wYXltZW50VG90YWwsIGlzU2lnbmVkV2l0aEFjdGl2ZUtleSwKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChhcGkuYXNzZXJ0KGlzVG9rZW5UcmFuc2ZlclZlcmlmaWVkKHJlcywgYXBpLnNlbmRlciwgaW5mby5hY2NvdW50LCBwcmljZVN5bWJvbCwgaW5mby5wYXltZW50VG90YWwsIGNvbnRyYWN0QWN0aW9uKSwgYHVuYWJsZSB0byB0cmFuc2ZlciBwYXltZW50IHRvICR7aW5mby5hY2NvdW50fWApKSB7CiAgICAgICAgICAgICAgc29sZE5mdHMgPSBzb2xkTmZ0cy5jb25jYXQoaW5mby5uZnRJZHMpOwogICAgICAgICAgICAgIHNlbGxlcnMucHVzaChpbmZvKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc29sZE5mdHMgPSBzb2xkTmZ0cy5jb25jYXQoaW5mby5uZnRJZHMpOwogICAgICAgICAgICBzZWxsZXJzLnB1c2goaW5mbyk7CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyB0cmFuc2ZlciBzb2xkIE5GVCBpbnN0YW5jZXMgdG8gbmV3IG93bmVyCiAgICAgICAgY29uc3QgbmZ0QXJyYXkgPSBbXTsKICAgICAgICBjb25zdCB3cmFwcGVkTmZ0cyA9IHsKICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgIGlkczogc29sZE5mdHMsCiAgICAgICAgfTsKICAgICAgICBuZnRBcnJheS5wdXNoKHdyYXBwZWROZnRzKTsKICAgICAgICBhd2FpdCBhcGkuZXhlY3V0ZVNtYXJ0Q29udHJhY3QoJ25mdCcsICd0cmFuc2ZlcicsIHsKICAgICAgICAgIGZyb21UeXBlOiAnY29udHJhY3QnLAogICAgICAgICAgdG86IGFwaS5zZW5kZXIsCiAgICAgICAgICB0b1R5cGU6ICd1c2VyJywKICAgICAgICAgIG5mdHM6IG5mdEFycmF5LAogICAgICAgICAgaXNTaWduZWRXaXRoQWN0aXZlS2V5LAogICAgICAgIH0pOwoKICAgICAgICAvLyBkZWxldGUgc29sZCBtYXJrZXQgb3JkZXJzCiAgICAgICAgY29uc3QgZ3JvdXBpbmdNYXAgPSB7fTsKICAgICAgICBjb25zdCBzb2xkU2V0ID0gbmV3IFNldChzb2xkTmZ0cyk7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBvcmRlcnMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICAgIGNvbnN0IG9yZGVyID0gb3JkZXJzW2ldOwogICAgICAgICAgaWYgKHNvbGRTZXQuaGFzKG9yZGVyLm5mdElkKSkgewogICAgICAgICAgICBhd2FpdCBhcGkuZGIucmVtb3ZlKG1hcmtldFRhYmxlTmFtZSwgb3JkZXIpOwoKICAgICAgICAgICAgY29uc3Qga2V5ID0gbWFrZUdyb3VwaW5nS2V5KG9yZGVyLmdyb3VwaW5nLCBuZnQuZ3JvdXBCeSk7CiAgICAgICAgICAgIGNvbnN0IGdyb3VwSW5mbyA9IGtleSBpbiBncm91cGluZ01hcAogICAgICAgICAgICAgID8gZ3JvdXBpbmdNYXBba2V5XQogICAgICAgICAgICAgIDogewogICAgICAgICAgICAgICAgZ3JvdXBpbmc6IG9yZGVyLmdyb3VwaW5nLAogICAgICAgICAgICAgICAgaXNJbkNvbGxlY3Rpb246IGZhbHNlLAogICAgICAgICAgICAgICAgY291bnQ6IDAsCiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgZ3JvdXBJbmZvLmNvdW50IC09IDE7CiAgICAgICAgICAgIGdyb3VwaW5nTWFwW2tleV0gPSBncm91cEluZm87CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyBhZGQgdGhlIHRyYWRlIHRvIHRoZSBoaXN0b3J5CiAgICAgICAgYXdhaXQgdXBkYXRlVHJhZGVzSGlzdG9yeSgnYnV5JywgYXBpLnNlbmRlciwgJ3UnLCBzZWxsZXJzLCBzeW1ib2wsIHByaWNlU3ltYm9sLCByZXF1aXJlZEJhbGFuY2UsIGZpbmFsTWFya2V0QWNjb3VudCwgZmVlVG90YWwsIHNvbGROZnRzLmxlbmd0aCk7CgogICAgICAgIGFwaS5lbWl0KCdoaXRTZWxsT3JkZXInLCB7CiAgICAgICAgICBzeW1ib2wsCiAgICAgICAgICBwcmljZVN5bWJvbCwKICAgICAgICAgIGFjY291bnQ6IGFwaS5zZW5kZXIsCiAgICAgICAgICBvd25lZEJ5OiAndScsCiAgICAgICAgICBzZWxsZXJzLAogICAgICAgICAgcGF5bWVudFRvdGFsLAogICAgICAgICAgZmVlVG90YWwsCiAgICAgICAgfSk7CgogICAgICAgIC8vIHVwZGF0ZSBvcGVuIGludGVyZXN0IG1ldHJpY3MKICAgICAgICBhd2FpdCB1cGRhdGVPcGVuSW50ZXJlc3QoJ3NlbGwnLCBzeW1ib2wsIHByaWNlU3ltYm9sLCBncm91cGluZ01hcCwgbmZ0Lmdyb3VwQnkpOwogICAgICB9CiAgICB9CiAgfQp9OwoKYWN0aW9ucy5zZWxsID0gYXN5bmMgKHBheWxvYWQpID0+IHsKICBjb25zdCB7CiAgICBzeW1ib2wsCiAgICBuZnRzLAogICAgcHJpY2UsCiAgICBwcmljZVN5b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CA9PT0gJ25mdCcKICAgICAgICAgICAgJiYgZXYuZXZlbnQgPT09ICd0cmFuc2ZlcicKICAgICAgICAgICAgJiYgZXYuZGF0YS5mcm9tID09PSBhcGkuc2VuZGVyCiAgICAgICAgICAgICYmIGV2LmRhdGEuZnJvbVR5cGUgPT09ICd1JwogICAgICAgICAgICAmJiBldi5kYXRhLnRvID09PSBDT05UUkFDVF9OQU1FCiAgICAgICAgICAgICYmIGV2LmRhdGEudG9UeXBlID09PSAnYycKICAgICAgICAgICAgJiYgZXYuZGF0YS5zeW1ib2wgPT09IHN5bWJvbCkgewogICAgICAgICAgICAvLyB0cmFuc2ZlciBpcyB2ZXJpZmllZCwgbm93IHdlIGNhbiBhZGQgYSBtYXJrZXQgb3JkZXIKICAgICAgICAgICAgY29uc3QgaW5zdGFuY2VJZCA9IGV2LmRhdGEuaWQ7CgogICAgICAgICAgICBjb25zdCBvcmRlckRhdGEgPSB7CiAgICAgICAgICAgICAgbmZ0SWQ6IGluc3RhbmNlSWQsCiAgICAgICAgICAgICAgZ3JvdXBpbmc6IHt9LAogICAgICAgICAgICAgIGdyb3VwaW5nS2V5OiAnJywKICAgICAgICAgICAgfTsKICAgICAgICAgICAgY29uc3QgaW50ZWdlcklkID0gYXBpLkJpZ051bWJlcihpbnN0YW5jZUlkKS50b051bWJlcigpOwogICAgICAgICAgICBuZnRJbnRlZ2VySWRMaXN0LnB1c2goaW50ZWdlcklkKTsKICAgICAgICAgICAgb3JkZXJEYXRhTWFwW2ludGVnZXJJZF0gPSBvcmRlckRhdGE7CiAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyBxdWVyeSBORlQgaW5zdGFuY2VzIHRvIGNvbnN0cnVjdCB0aGUgZ3JvdXBpbmcKICAgICAgICBjb25zdCBpbnN0YW5jZXMgPSBhd2FpdCBhcGkuZGIuZmluZEluVGFibGUoCiAgICAgICAgICAnbmZ0JywKICAgICAgICAgIGluc3RhbmNlVGFibGVOYW1lLAogICAgICAgICAgewogICAgICAgICAgICBfaWQ6IHsKICAgICAgICAgICAgICAkaW46IG5mdEludGVnZXJJZExpc3QsCiAgICAgICAgICAgIH0sCiAgICAgICAgICB9LAogICAgICAgICAgTUFYX05VTV9VTklUU19PUEVSQUJMRSwKICAgICAgICAgIDAsCiAgICAgICAgICBbeyBpbmRleDogJ19pZCcsIGRlc2NlbmRpbmc6IGZhbHNlIH1dLAogICAgICAgICk7CgogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5zdGFuY2VzLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBjb25zdCBpbnN0YW5jZSA9IGluc3RhbmNlc1tqXTsKICAgICAgICAgIGNvbnN0IGdyb3VwaW5nID0ge307CiAgICAgICAgICBsZXQgZ3JvdXBpbmdLZXkgPSAnJzsKICAgICAgICAgIG5mdC5ncm91cEJ5LmZvckVhY2goKG5hbWUpID0+IHsKICAgICAgICAgICAgaWYgKGluc3RhbmNlLnByb3BlcnRpZXNbbmFtZV0gIT09IHVuZGVmaW5lZCAmJiBpbnN0YW5jZS5wcm9wZXJ0aWVzW25hbWVdICE9PSBudWxsKSB7CiAgICAgICAgICAgICAgZ3JvdXBpbmdbbmFtZV0gPSBpbnN0YW5jZS5wcm9wZXJ0aWVzW25hbWVdLnRvU3RyaW5nKCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZ3JvdXBpbmdbbmFtZV0gPSAnJzsKICAgICAgICAgICAgfQogICAgICAgICAgICBncm91cGluZ0tleSA9IGdyb3VwaW5nS2V5ICsgJzonICsgbmFtZSArICc6JyArIGdyb3VwaW5nW25hbWVdOwogICAgICAgICAgfSk7CiAgICAgICAgICBvcmRlckRhdGFNYXBbaW5zdGFuY2UuX2lkXS5ncm91cGluZyA9IGdyb3VwaW5nOwogICAgICAgICAgb3JkZXJEYXRhTWFwW2luc3RhbmNlLl9pZF0uZ3JvdXBpbmdLZXkgPSBncm91cGluZ0tleTsKICAgICAgICB9CgogICAgICAgIC8vIGNyZWF0ZSB0aGUgb3JkZXJzCiAgICAgICAgY29uc3QgZ3JvdXBpbmdNYXAgPSB7fTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IG5mdEludGVnZXJJZExpc3QubGVuZ3RoOyBrICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGludElkID0gbmZ0SW50ZWdlcklkTGlzdFtrXTsKICAgICAgICAgIGNvbnN0IG9yZGVySW5mbyA9IG9yZGVyRGF0YU1hcFtpbnRJZF07CiAgICAgICAgICBjb25zdCBvcmRlciA9IHsKICAgICAgICAgICAgYWNjb3VudDogYXBpLnNlbmRlciwKICAgICAgICAgICAgb3duZWRCeTogJ3UnLAogICAgICAgICAgICBuZnRJZDogb3JkZXJJbmZvLm5mdElkLAogICAgICAgICAgICBncm91cGluZzogb3JkZXJJbmZvLmdyb3VwaW5nLAogICAgICAgICAgICB0aW1lc3RhbXAsCiAgICAgICAgICAgIHByaWNlOiBmaW5hbFByaWNlLAogICAgICAgICAgICBwcmljZURlYzogeyAkbnVtYmVyRGVjaW1hbDogZmluYWxQcmljZSB9LAogICAgICAgICAgICBwcmljZVN5bWJvbCwKICAgICAgICAgICAgZmVlLAogICAgICAgICAgfTsKCiAgICAgICAgICBjb25zdCByZXN1bHQgPSBhd2FpdCBhcGkuZGIuaW5zZXJ0KG1hcmtldFRhYmxlTmFtZSwgb3JkZXIpOwoKICAgICAgICAgIGFwaS5lbWl0KCdzZWxsT3JkZXInLCB7CiAgICAgICAgICAgIGFjY291bnQ6IG9yZGVyLmFjY291bnQsCiAgICAgICAgICAgIG93bmVkQnk6IG9yZGVyLm93bmVkQnksCiAgICAgICAgICAgIHN5bWJvbCwKICAgICAgICAgICAgbmZ0SWQ6IG9yZGVyLm5mdElkLAogICAgICAgICAgICB0aW1lc3RhbXAsCiAgICAgICAgICAgIHByaWNlOiBvcmRlci5wcmljZSwKICAgICAgICAgICAgcHJpY2VTeW1ib2w6IG9yZGVyLnByaWNlU3ltYm9sLAogICAgICAgICAgICBmZWUsCiAgICAgICAgICAgIG9yZGVySWQ6IHJlc3VsdC5faWQsCiAgICAgICAgICB9KTsKCiAgICAgICAgICBjb25zdCBncm91cEluZm8gPSBvcmRlckluZm8uZ3JvdXBpbmdLZXkgaW4gZ3JvdXBpbmdNYXAKICAgICAgICAgICAgPyBncm91cGluZ01hcFtvcmRlckluZm8uZ3JvdXBpbmdLZXldCiAgICAgICAgICAgIDogewogICAgICAgICAgICAgIGdyb3VwaW5nOiBvcmRlckluZm8uZ3JvdXBpbmcsCiAgICAgICAgICAgICAgaXNJbkNvbGxlY3Rpb246IGZhbHNlLAogICAgICAgICAgICAgIGNvdW50OiAwLAogICAgICAgICAgICB9OwogICAgICAgICAgZ3JvdXBJbmZvLmNvdW50ICs9IDE7CiAgICAgICAgICBncm91cGluZ01hcFtvcmRlckluZm8uZ3JvdXBpbmdLZXldID0gZ3JvdXBJbmZvOwogICAgICAgIH0KCiAgICAgICAgLy8gdXBkYXRlIG9wZW4gaW50ZXJlc3QgbWV0cmljcwogICAgICAgIGF3YWl0IHVwZGF0ZU9wZW5JbnRlcmVzdCgnc2VsbCcsIHN5bWJvbCwgcHJpY2VTeW1ib2wsIGdyb3VwaW5nTWFwLCBuZnQuZ3JvdXBCeSk7CiAgICAgIH0KICAgIH0KICB9Cn07Cg=="
}
}
}