-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
6,309 additions
and
1,129 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{ | ||
"methods": { | ||
"set_metadata": { | ||
"argument": "manastation.set_metadata_arguments", | ||
"return": "manastation.empty_object", | ||
"description": "Set contract metadata", | ||
"entry_point": 1029287705, | ||
"read_only": false | ||
}, | ||
"authorize": { | ||
"argument": "koinos.chain.authorize_arguments", | ||
"return": "koinos.chain.authorize_result", | ||
"description": "Check if authorized", | ||
"entry_point": 1244511632, | ||
"read_only": false | ||
}, | ||
"get_metadata": { | ||
"argument": "manastation.get_metadata_arguments", | ||
"return": "manastation.metadata_object", | ||
"description": "Get contract metadata", | ||
"entry_point": 4244088463, | ||
"read_only": true | ||
} | ||
}, | ||
"types": { | ||
"nested": { | ||
"manastation": { | ||
"nested": { | ||
"set_metadata_arguments": { | ||
"fields": { | ||
"nameservice_address": { | ||
"type": "bytes", | ||
"id": 1, | ||
"options": { | ||
"(koinos.btype)": "CONTRACT_ID" | ||
} | ||
}, | ||
"max_rc_limit": { | ||
"type": "uint64", | ||
"id": 2 | ||
} | ||
} | ||
}, | ||
"get_metadata_arguments": { | ||
"fields": {} | ||
}, | ||
"balance_of_args": { | ||
"fields": { | ||
"owner": { | ||
"type": "bytes", | ||
"id": 1, | ||
"options": { | ||
"(koinos.btype)": "ADDRESS" | ||
} | ||
} | ||
} | ||
}, | ||
"balance_of_res": { | ||
"fields": { | ||
"value": { | ||
"type": "uint64", | ||
"id": 1, | ||
"options": { | ||
"jstype": "JS_STRING" | ||
} | ||
} | ||
} | ||
}, | ||
"empty_object": { | ||
"fields": {} | ||
}, | ||
"metadata_object": { | ||
"fields": { | ||
"nameservice_address": { | ||
"type": "bytes", | ||
"id": 1, | ||
"options": { | ||
"(koinos.btype)": "CONTRACT_ID" | ||
} | ||
}, | ||
"max_rc_limit": { | ||
"type": "uint64", | ||
"id": 2 | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"koinos": { | ||
"nested": { | ||
"chain": { | ||
"options": { | ||
"go_package": "github.com/koinos/koinos-proto-golang/koinos/chain" | ||
}, | ||
"nested": { | ||
"authorization_type": { | ||
"values": { | ||
"contract_call": 0, | ||
"transaction_application": 1, | ||
"contract_upload": 2 | ||
} | ||
}, | ||
"call_target": { | ||
"fields": { | ||
"contract_id": { | ||
"type": "bytes", | ||
"id": 1, | ||
"options": { | ||
"(btype)": "ADDRESS" | ||
} | ||
}, | ||
"entry_point": { | ||
"type": "uint32", | ||
"id": 2 | ||
} | ||
} | ||
}, | ||
"authorize_arguments": { | ||
"oneofs": { | ||
"_call": { | ||
"oneof": [ | ||
"call" | ||
] | ||
} | ||
}, | ||
"fields": { | ||
"type": { | ||
"type": "authorization_type", | ||
"id": 1 | ||
}, | ||
"call": { | ||
"type": "call_target", | ||
"id": 2, | ||
"options": { | ||
"proto3_optional": true | ||
} | ||
} | ||
} | ||
}, | ||
"authorize_result": { | ||
"fields": { | ||
"value": { | ||
"type": "bool", | ||
"id": 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"methods": { | ||
"set_metadata": { | ||
"argument": "manastation.set_metadata_arguments", | ||
"return": "manastation.empty_object", | ||
"description": "Set contract metadata", | ||
"entry-point": "0x3d59af19", | ||
"read-only": false | ||
}, | ||
"get_metadata": { | ||
"argument": "manastation.get_metadata_arguments", | ||
"return": "manastation.metadata_object", | ||
"description": "Get contract metadata", | ||
"entry-point": "0xfcf7a68f", | ||
"read-only": true | ||
} | ||
}, | ||
"types": "CrEDCiBhc3NlbWJseS9wcm90by9tYW5hc3RhdGlvbi5wcm90bxILbWFuYXN0YXRpb24aFGtvaW5vcy9vcHRpb25zLnByb3RvInEKFnNldF9tZXRhZGF0YV9hcmd1bWVudHMSNQoTbmFtZXNlcnZpY2VfYWRkcmVzcxgBIAEoDEIEgLUYBVISbmFtZXNlcnZpY2VBZGRyZXNzEiAKDG1heF9yY19saW1pdBgCIAEoBFIKbWF4UmNMaW1pdCIYChZnZXRfbWV0YWRhdGFfYXJndW1lbnRzIi0KD2JhbGFuY2Vfb2ZfYXJncxIaCgVvd25lchgBIAEoDEIEgLUYBlIFb3duZXIiKgoOYmFsYW5jZV9vZl9yZXMSGAoFdmFsdWUYASABKARCAjABUgV2YWx1ZSIOCgxlbXB0eV9vYmplY3QiagoPbWV0YWRhdGFfb2JqZWN0EjUKE25hbWVzZXJ2aWNlX2FkZHJlc3MYASABKAxCBIC1GAVSEm5hbWVzZXJ2aWNlQWRkcmVzcxIgCgxtYXhfcmNfbGltaXQYAiABKARSCm1heFJjTGltaXRiBnByb3RvMwrnAwoca29pbm9zL2NoYWluL2F1dGhvcml0eS5wcm90bxIMa29pbm9zLmNoYWluGhRrb2lub3Mvb3B0aW9ucy5wcm90byJVCgtjYWxsX3RhcmdldBIlCgtjb250cmFjdF9pZBgBIAEoDEIEgLUYBlIKY29udHJhY3RJZBIfCgtlbnRyeV9wb2ludBgCIAEoDVIKZW50cnlQb2ludCKIAQoTYXV0aG9yaXplX2FyZ3VtZW50cxI0CgR0eXBlGAEgASgOMiAua29pbm9zLmNoYWluLmF1dGhvcml6YXRpb25fdHlwZVIEdHlwZRIyCgRjYWxsGAIgASgLMhkua29pbm9zLmNoYWluLmNhbGxfdGFyZ2V0SABSBGNhbGyIAQFCBwoFX2NhbGwiKAoQYXV0aG9yaXplX3Jlc3VsdBIUCgV2YWx1ZRgBIAEoCFIFdmFsdWUqWQoSYXV0aG9yaXphdGlvbl90eXBlEhEKDWNvbnRyYWN0X2NhbGwQABIbChd0cmFuc2FjdGlvbl9hcHBsaWNhdGlvbhABEhMKD2NvbnRyYWN0X3VwbG9hZBACQjRaMmdpdGh1Yi5jb20va29pbm9zL2tvaW5vcy1wcm90by1nb2xhbmcva29pbm9zL2NoYWluYgZwcm90bzM=" | ||
} |
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
contracts/mana-station/assembly/Manastation.boilerplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { System, Protobuf, authority } from "@koinos/sdk-as"; | ||
import { manastation } from "./proto/manastation"; | ||
|
||
export class Manastation { | ||
authorize(args: authority.authorize_arguments): authority.authorize_result { | ||
// const call = args.call; | ||
// const type = args.type; | ||
|
||
// YOUR CODE HERE | ||
|
||
const res = new authority.authorize_result(); | ||
res.value = true; | ||
|
||
return res; | ||
} | ||
|
||
set_metadata( | ||
args: manastation.set_metadata_arguments | ||
): manastation.empty_object { | ||
// const nameservice_address = args.nameservice_address; | ||
// const max_rc_limit = args.max_rc_limit; | ||
|
||
// YOUR CODE HERE | ||
|
||
const res = new manastation.empty_object(); | ||
|
||
return res; | ||
} | ||
|
||
get_metadata( | ||
args: manastation.get_metadata_arguments | ||
): manastation.metadata_object { | ||
// YOUR CODE HERE | ||
|
||
const res = new manastation.metadata_object(); | ||
// res.nameservice_address = ; | ||
// res.max_rc_limit = ; | ||
|
||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { authority, Crypto, Protobuf, System, value } from "@koinos/sdk-as"; | ||
import { manastation } from './proto/manastation'; | ||
import { Metadata } from "./state/Metadata"; | ||
|
||
const BALANCE_OF_ENTRYPOINT = 0x5c721497; | ||
|
||
export class Manastation { | ||
contractId: Uint8Array = System.getContractId(); | ||
metadata: Metadata = new Metadata(this.contractId); | ||
|
||
private hasKapName(address: Uint8Array, nameserviceAddress: Uint8Array): bool { | ||
const args = new manastation.balance_of_args(address); | ||
|
||
const callRes = System.call( | ||
nameserviceAddress, | ||
BALANCE_OF_ENTRYPOINT, | ||
Protobuf.encode(args, manastation.balance_of_args.encode) | ||
); | ||
System.require(callRes.code == 0, "failed to retrieve KAP balance"); | ||
const res = Protobuf.decode<manastation.balance_of_res>( | ||
callRes.res.object!, | ||
manastation.balance_of_res.decode | ||
); | ||
|
||
return res.value > 0; | ||
} | ||
|
||
/* | ||
* Recover an address from a signature and transactionId | ||
*/ | ||
private recoverAddressFromSignature(signature: Uint8Array, transactionId: Uint8Array): Uint8Array { | ||
return Crypto.addressFromPublicKey(System.recoverPublicKey(signature, transactionId)!); | ||
} | ||
|
||
/* | ||
* Check if an address was used to sign the transaction | ||
*/ | ||
private checkIfAnySignerHasKapName(signatures: value.list_type, transactionId: Uint8Array, nameserviceAddress: Uint8Array): bool { | ||
let addr: Uint8Array; | ||
|
||
for (let i = 0; i < signatures.values.length; i++) { | ||
addr = this.recoverAddressFromSignature( | ||
signatures.values[i].bytes_value!, | ||
transactionId | ||
); | ||
|
||
if (this.hasKapName(addr, nameserviceAddress)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
authorize(_: authority.authorize_arguments): authority.authorize_result { | ||
// const metadata = this.metadata.get()!; | ||
|
||
// const transactionId = System.getTransactionField('id')!.bytes_value!; | ||
// const signatures = Protobuf.decode<value.list_type>(System.getTransactionField('signatures')!.message_value!.value!, value.list_type.decode); | ||
// const rcLimit = System.getTransactionField('header.rc_limit')!.uint64_value; | ||
|
||
// return new authority.authorize_result(rcLimit <= metadata.max_rc_limit && this.checkIfAnySignerHasKapName(signatures, transactionId, metadata.nameservice_address!)); | ||
|
||
return new authority.authorize_result(true); | ||
} | ||
|
||
set_metadata( | ||
args: manastation.set_metadata_arguments | ||
): manastation.empty_object { | ||
// only this contract can set the metadata for now | ||
System.requireAuthority( | ||
authority.authorization_type.contract_call, | ||
this.contractId | ||
); | ||
|
||
const nameservice_address = args.nameservice_address; | ||
const max_rc_limit = args.max_rc_limit; | ||
|
||
this.metadata.put( | ||
new manastation.metadata_object( | ||
nameservice_address, | ||
max_rc_limit, | ||
) | ||
); | ||
|
||
return new manastation.empty_object(); | ||
} | ||
|
||
get_metadata( | ||
_: manastation.get_metadata_arguments | ||
): manastation.metadata_object { | ||
return this.metadata.get()!; | ||
} | ||
} |
Oops, something went wrong.