/// <summary> /// Removes the master account from the registered MasterAccounts /// </summary> /// <param name="args"></param> /// <returns></returns> public static object RemoveMasterAccount(object[] args) { if (args.Length != 1) { return(false); } byte[] removedAccount = (byte[])args[0]; if (removedAccount.Length != 20) { return(false); } //if (!Runtime.CheckWitness(AppGlobals.TrustedSourceScriptHash)) //{ // Runtime.Log("Caller isn't the trusted source"); // return false; //} byte[] masterAccounts = BankDao.GetMasterAccounts(); if (masterAccounts.Length == 0) { Runtime.Log("Contract not deployed. Execute Deploy() before using."); return(false); } Map <byte[], object> masterAccountsObjects = (Map <byte[], object>)masterAccounts.Deserialize(); if (!masterAccountsObjects.HasKey(removedAccount)) { Runtime.Log("Master Account not found for deletion"); return(false); } masterAccountsObjects.Remove(removedAccount); BankDao.UpdateMasterAccounts(masterAccountsObjects.Serialize()); return(true); }
/// <summary> /// Method that must be called before using this smart contract. /// It will start the storage and also deploy the genesis master account. /// </summary> /// <returns></returns> public static object Deploy() { //if (Runtime.CheckWitness(AppGlobals.TrustedSourceScriptHash)) //{ Runtime.Log("Deploying contract"); byte[] existingMasterAccounts = BankDao.GetMasterAccounts(); if (existingMasterAccounts.Length != 0) { Runtime.Log("Contract already deployed"); return(false); } Map <byte[], object> masterAccountsObjects = new Map <byte[], object>(); var genesisMasterAccount = CreateMasterAccount("Genesis Master Account", "*****@*****.**", "Simpli Tech", "+55 11 3280-5541"); masterAccountsObjects[AppGlobals.TrustedSourceScriptHash] = genesisMasterAccount; BankDao.UpdateMasterAccounts(masterAccountsObjects.Serialize()); return(true); //} //else{ // Runtime.Log("This account is not authorized to deploy this contract."); // return false; //} }
/// <summary> /// Register a Master account and add this information into the storage /// </summary> /// <param name="args">ScriptHash, EntityName, EntityAddress, EntityPhone, EntityConactEmail</param> /// <returns></returns> public static object RegisterMasterAccount(object[] args) { for (int i = 0; i < args.Length; i++) { string asstr = (string)args[i]; Runtime.Log(asstr); } if (args.Length != 5) { Runtime.Log("Invalid parameters for RegisterMasterAccount"); return(false); } byte[] newAccount = (byte[])args[0]; if (newAccount.Length != 20) { Runtime.Log("Invalid account for RegisterMasterAccount"); return(false); } string entityName = (string)args[1]; if (entityName.Length == 0) { Runtime.Log("Invalid entity name"); return(false); } string entityAddress = (string)args[2]; if (entityAddress.Length == 0) { Runtime.Log("Invalid entity address"); return(false); } string entityPhone = (string)args[3]; if (entityPhone.Length == 0) { Runtime.Log("Invalid entity phone"); return(false); } string entityEmail = (string)args[4]; if (entityEmail.Length == 0) { Runtime.Log("Invalid entity e-mail"); return(false); } //if (!Runtime.CheckWitness(AppGlobals.TrustedSourceScriptHash)) //{ // Runtime.Log("Caller isn't the trusted source"); // return false; //} byte[] masterAccounts = BankDao.GetMasterAccounts(); if (masterAccounts.Length == 0) { Runtime.Log("Contract not deployed. Call Deploy() before using."); return(false); } Map <byte[], object> masterAccountsObjects = (Map <byte[], object>)masterAccounts.Deserialize(); Map <string, object> masterAccount = new Map <string, object>(); if (masterAccountsObjects.HasKey(newAccount)) { Runtime.Log("Account exists"); masterAccount = (Map <string, object>)masterAccountsObjects[newAccount]; } //Update the account masterAccount = CreateMasterAccount(entityAddress, entityEmail, entityName, entityPhone); masterAccountsObjects[newAccount] = masterAccount; BankDao.UpdateMasterAccounts(masterAccountsObjects.Serialize()); Notifier.NotifyNewMasterAccount(newAccount); return(true); }