public static IPromise <TournamentCreateOperationData> GenerateCreateTournamentOperation(CreateTournamentData data) { Func <AssetObject, IPromise <TournamentCreateOperationData> > GenerateOperation = assetObject => Promise <TournamentCreateOperationData> .Resolved(new TournamentCreateOperationData { Fee = new AssetData(0L, assetObject.Id), Creator = data.account, Options = new TournamentOptionsData { RegistrationDeadline = data.registrationDeadline, NumberOfPlayers = data.numberOfPlayers, BuyIn = new AssetData(( long )(data.buyInAmount * Math.Pow(10, assetObject.Precision)), assetObject.Id), Whitelist = data.whitelist.OrEmpty(), StartTime = data.startTime, StartDelay = data.startDelay, RoundDelay = data.roundDelay, NumberOfWins = data.numberOfWins, Meta = new CustomData(), GameOptions = new RockPaperScissorsGameOptionsData { InsuranceEnabled = data.insuranceEnabled, TimePerCommitMove = data.timePerCommitMove, TimePerRevealMove = data.timePerRevealMove } } }); var asset = SpaceTypeId.CreateOne(SpaceType.Asset, data.buyInAssetId); return(Repository.GetInPromise(asset, () => ApiManager.Instance.Database.GetAsset(asset.Id)).Then(GenerateOperation)); }
public IPromise <string> QueryContract(uint contractId, string bytecode, uint feeAssetId = 0, long amount = 0) { if (!Authorization.IsAuthorized) { return(Promise <string> .Rejected(new InvalidOperationException("Isn't Authorized!"))); } var value = new AssetData(amount, SpaceTypeId.CreateOne(SpaceType.Asset, feeAssetId)); return(Database.CallContractNoChangingState(contractId, Authorization.Current.UserNameData.Value.Account.Id.ToUintId, value, bytecode)); }
// Typically this is called automatically just prior to signing. Once finalized this transaction can not be changed. private IPromise Finalize() { if (IsFinalized) { return(Promise.Rejected(new InvalidOperationException("Finalize... Already finalized"))); } var dynamicGlobalProperties = SpaceTypeId.CreateOne(SpaceType.DynamicGlobalProperties); return(Repository.GetInPromise(dynamicGlobalProperties, () => EchoApiManager.Instance.Database.GetObject <DynamicGlobalPropertiesObject>(dynamicGlobalProperties)).Then(FinalizeInPromise)); }
public void SetUp(TournamentObject tournament) { ApiManager.Instance.Database .GetAccountBalances(AuthorizationManager.Instance.UserData.FullAccount.Account.Id.Id, Array.ConvertAll(AuthorizationManager.Instance.UserData.FullAccount.Balances, balance => balance.AssetType.Id)) .Then(accountBalances => { AssetData asset = null; foreach (var balance in accountBalances) { if (balance.Asset.Equals(tournament.Options.BuyIn.Asset)) { asset = balance; } } var feeAsset = SpaceTypeId.CreateOne(SpaceType.GlobalProperties); Repository.GetInPromise <GlobalPropertiesObject>(feeAsset) .Then(result => { TournamentJoinOperationFeeParametersData myFee = null; foreach (var fee in result.Parameters.CurrentFees.Parameters) { if (fee != null && fee.Type == ChainTypes.FeeParameters.TournamentJoinOperation) { myFee = fee as TournamentJoinOperationFeeParametersData; } } currentAccountBalanceObject = asset; currentFee = (long)myFee.Fee; Repository.GetInPromise <AssetObject>(asset.Asset) .Then(assetObject => { buyinText.text = tournament.Options.BuyIn.Amount / Math.Pow(10, assetObject.Precision) + assetObject.Symbol; feeText.text = myFee.Fee / Math.Pow(10, assetObject.Precision) + assetObject.Symbol; ApiManager.Instance.Database.GetAccount(tournament.Creator.Id) .Then(creator => { creatorNameText.text = Utils.GetFormatedString(creator.Name); var data = new JoinToTournamentData(); data.tournament = tournament; data.account = AuthorizationManager.Instance.UserData.FullAccount.Account.Id; currentData = data; gameTitleText.text = "ROCK, PAPER, SCISSORS"; numberOfPlayersText.text = data.tournament.Options.NumberOfPlayers.ToString(); winsAmountText.text = data.tournament.Options.NumberOfWins.ToString(); registrationDeadlineText.text = data.tournament.Options.RegistrationDeadline.ToString("MMMM dd, yyyy hh:mmtt (z)").ToUpper(); Show(); }); }); }); }); }
public void SetUp(TournamentObject tournament) { ApiManager.Instance.Database .GetAccountBalances(AuthorizationManager.Instance.UserData.FullAccount.Account.Id.Id, Array.ConvertAll(AuthorizationManager.Instance.UserData.FullAccount.Balances, balance => balance.AssetType.Id)) .Then(accountBalances => { var data = new LeaveFromTournamentData(); data.tournament = tournament; data.account = AuthorizationManager.Instance.UserData.FullAccount.Account.Id; currentData = data; AssetData asset = null; foreach (var balance in accountBalances) { if (balance.Asset.Equals(currentData.tournament.Options.BuyIn.Asset)) { asset = balance; } } TournamentTransactionService.GenerateLeaveFromTournamentOperation(currentData) .Then(operation => { var feeAsset = SpaceTypeId.CreateOne(SpaceType.Asset); ApiManager.Instance.Database.GetRequiredFee(operation, feeAsset.Id) .Then(feeResult => { Repository.GetInPromise <AssetObject>(feeResult.Asset) .Then(assetData => { buyinText.text = tournament.Options.BuyIn.Amount / Math.Pow(10, assetData.Precision) + assetData.Symbol; feeText.text = feeResult.Amount / Math.Pow(10, assetData.Precision) + assetData.Symbol; currentFee = feeResult.Amount; currentOperation = operation; currentAccountBalanceObject = asset; ApiManager.Instance.Database.GetAccount(tournament.Creator.Id) .Then(creator => { gameTitleText.text = "ROCK, PAPER, SCISSORS"; creatorNameText.text = Utils.GetFormatedString(creator.Name); numberOfPlayersText.text = data.tournament.Options.NumberOfPlayers.ToString(); winsAmountText.text = data.tournament.Options.NumberOfWins.ToString(); registrationDeadlineText.text = data.tournament.Options.RegistrationDeadline.ToString("MMMM dd, yyyy hh:mmtt (z)").ToUpper(); Show(); }); }) .Catch(exception => OperationOnDone("There was a mistake during leaving of a tournament!", false)); }) .Catch(exception => OperationOnDone("There was a mistake during leaving of a tournament!", false)); }) .Catch(exception => OperationOnDone("There was a mistake during leaving of a tournament!", false)); }); }
public IPromise DeployContract(string bytecode, uint feeAssetId = 0, Action <TransactionConfirmationData> resultCallback = null) { if (!Authorization.IsAuthorized) { return(Promise.Rejected(new InvalidOperationException("Isn't Authorized!"))); } var operation = new ContractCallOperationData { Registrar = SpaceTypeId.CreateOne(SpaceType.Account, Authorization.Current.UserNameData.Value.Account.Id.ToUintId), Value = new AssetData(0, SpaceTypeId.CreateOne(SpaceType.Asset, feeAssetId)), Code = bytecode.OrEmpty(), Callee = null }; return(Authorization.ProcessTransaction(new TransactionBuilder().AddOperation(operation), operation.Value.AssetId, resultCallback)); }
public void SetTournamentInformation(CreateTournamentData data, bool isJoin) { isJoinToTournament = isJoin; currentData = data; gameTitleText.text = "ROCK, PAPER, SCISSORS"; var username = AuthorizationManager.Instance.Authorization.UserNameData.UserName; creatorNameText.text = Utils.GetFormatedString(username); numberOfPlayersText.text = data.numberOfPlayers.ToString(); winsAmountText.text = data.numberOfWins.ToString(); registrationDeadlineText.text = data.registrationDeadline.ToString("MMMM dd, yyyy hh:mmtt (z)").ToUpper(); TournamentManager.Instance.GetAssetObject(data.buyInAssetId) .Then(asset => { buyinText.text = Utils.GetFormatedDecimaNumber(data.buyInAmount.ToString()) + asset.Symbol; var feeAsset = SpaceTypeId.CreateOne(SpaceType.GlobalProperties); Repository .GetInPromise <GlobalPropertiesObject>(feeAsset) .Then(result => { TournamentJoinOperationFeeParametersData joinFee = null; TournamentCreateOperationFeeParametersData createFee = null; foreach (var fee in result.Parameters.CurrentFees.Parameters) { if (fee != null && fee.Type == ChainTypes.FeeParameters.TournamentJoinOperation) { joinFee = fee as TournamentJoinOperationFeeParametersData; } if (fee != null && fee.Type == ChainTypes.FeeParameters.TournamentCreateOperation) { createFee = fee as TournamentCreateOperationFeeParametersData; } } var amount = isJoin ? Convert.ToDouble(createFee.Fee + joinFee.Fee) : Convert.ToDouble(createFee.Fee); amount /= Mathf.Pow(10, asset.Precision); feeText.text = amount + asset.Symbol; gameObject.SetActive(true); }); }); }
public TransactionBuilder AddOperation(OperationData operation) { if (IsFinalized) { throw new InvalidOperationException("AddOperation... Already finalized"); } if (operation.Fee.IsNull()) { operation.Fee = new AssetData(0, SpaceTypeId.CreateOne(SpaceType.Asset)); } if (operation.Type.Equals(ChainTypes.Operation.ProposalCreate)) { var proposalCreateOperation = (ProposalCreateOperationData)operation; if (proposalCreateOperation.ExpirationTime.IsZero()) { proposalCreateOperation.ExpirationTime = TimeTool.ZeroTime().AddSeconds(BaseExpirationSeconds + ChainConfig.ExpireInSecondsProposal); } } operations.Add(operation); return(this); }
public static IPromise <TransactionBuilder> SetRequiredFees(TransactionBuilder builder, SpaceTypeId assetId = null) { if (builder.IsFinalized) { throw new InvalidOperationException("SetRequiredFees... Already finalized"); } if (builder.operations.IsNullOrEmpty()) { throw new InvalidOperationException("SetRequiredFees... Add operation first"); } var ops = new OperationData[builder.operations.Count]; for (var i = 0; i < builder.operations.Count; i++) { ops[i] = builder.operations[i].Clone(); } var coreAssetId = SpaceTypeId.CreateOne(SpaceType.Asset); if (assetId.IsNull()) { var firstFee = ops.First().Fee; if (!firstFee.IsNull() && !firstFee.AssetId.IsNullOrEmpty()) { assetId = firstFee.AssetId; } else { assetId = coreAssetId; } } var isNotCoreAsset = !assetId.Equals(coreAssetId); var promises = new List <IPromise <object> >(); if (ops.Contains(op => op.Type.Equals(ChainTypes.Operation.ContractCall))) { promises.Add(EchoApiManager.Instance.Database.GetRequiredFees <FeeForCallContractData>(ops, assetId.ToUintId).Then <object>(feesData => feesData.Cast <IFeeAsset>())); if (isNotCoreAsset) { promises.Add(EchoApiManager.Instance.Database.GetRequiredFees <FeeForCallContractData>(ops, coreAssetId.ToUintId).Then <object>(coreFeesData => coreFeesData.Cast <IFeeAsset>())); } } else if (ops.Contains(op => op.Type.Equals(ChainTypes.Operation.ContractCreate))) { promises.Add(EchoApiManager.Instance.Database.GetRequiredFees <FeeForCreateContractData>(ops, assetId.ToUintId).Then <object>(feesData => feesData.Cast <IFeeAsset>())); if (isNotCoreAsset) { promises.Add(EchoApiManager.Instance.Database.GetRequiredFees <FeeForCreateContractData>(ops, coreAssetId.ToUintId).Then <object>(coreFeesData => coreFeesData.Cast <IFeeAsset>())); } } else { promises.Add(EchoApiManager.Instance.Database.GetRequiredFees <AssetData>(ops, assetId.ToUintId).Then <object>(feesData => feesData.Cast <IFeeAsset>())); if (isNotCoreAsset) { promises.Add(EchoApiManager.Instance.Database.GetRequiredFees <AssetData>(ops, coreAssetId.ToUintId).Then <object>(coreFeesData => coreFeesData.Cast <IFeeAsset>())); } } if (isNotCoreAsset) { promises.Add(Repository.GetInPromise(assetId, () => EchoApiManager.Instance.Database.GetAsset(assetId.ToUintId)).Then <object>(assetObject => assetObject)); } return(Promise <object> .All(promises.ToArray()).Then(results => { var list = new List <object>(results).ToArray(); var feesData = list.First() as IFeeAsset[]; var coreFeesData = (list.Length > 1) ? (list[1] as IFeeAsset[]) : null; var assetObject = (list.Length > 2) ? (list[2] as AssetObject) : null; var dynamicPromise = isNotCoreAsset ? EchoApiManager.Instance.Database.GetObject <AssetDynamicDataObject>(assetObject.DynamicAssetData) : Promise <AssetDynamicDataObject> .Resolved(null); return dynamicPromise.Then(dynamicObject => { if (isNotCoreAsset) { var totalFees = 0L; for (var j = 0; j < coreFeesData.Length; j++) { totalFees += coreFeesData[j].FeeAsset.Amount; } var feePool = dynamicObject.IsNull() ? 0L : dynamicObject.FeePool; if (totalFees > feePool) { feesData = coreFeesData; } } var flatAssets = GetFee(feesData.OrEmpty(), new List <AssetData>()); var assetIndex = 0; for (var i = 0; i < builder.operations.Count; i++) { SetFee(builder.operations[i], ref assetIndex, flatAssets); } }); }).Then(() => Promise <TransactionBuilder> .Resolved(builder))); }
public IPromise <AccountObject> GetAccount(uint id) { return(GetObject <AccountObject>(SpaceTypeId.CreateOne(SpaceType.Account, id))); }
public IPromise <AssetObject> GetAsset(uint id = 0) { return(GetObject <AssetObject>(SpaceTypeId.CreateOne(SpaceType.Asset, id))); }
// Optional: the fees can be obtained from the witness node public static IPromise <TransactionBuilder> SetRequiredFees(TransactionBuilder builder, SpaceTypeId asset = null) { var feePool = 0L; if (builder.IsFinalized) { throw new InvalidOperationException("SetRequiredFees... Already finalized"); } if (builder.operations.IsNullOrEmpty()) { throw new InvalidOperationException("SetRequiredFees... Add operation first"); } var ops = new OperationData[builder.operations.Count]; for (var i = 0; i < builder.operations.Count; i++) { ops[i] = builder.operations[i].Clone(); } var zeroAsset = SpaceTypeId.CreateOne(SpaceType.Asset); if (asset.IsNull()) { var firstFee = ops[0].Fee; if (!firstFee.IsNull() && !firstFee.Asset.IsNullOrEmpty()) { asset = firstFee.Asset; } else { asset = zeroAsset; } } var promises = new List <IPromise <object> >(); promises.Add(ApiManager.Instance.Database.GetRequiredFees(ops, asset.Id).Then <object>(feesData => feesData)); if (!asset.Equals(zeroAsset)) { // This handles the fallback to paying fees in BTS if the fee pool is empty. promises.Add(ApiManager.Instance.Database.GetRequiredFees(ops, zeroAsset.Id).Then <object>(coreFeesData => coreFeesData)); promises.Add(Repository.GetInPromise(asset, () => ApiManager.Instance.Database.GetAsset(asset.Id)).Then <object>(assetObject => assetObject)); } return(Promise <object> .All(promises.ToArray()).Then(results => { var list = new List <object>(results).ToArray(); var feesData = list[0] as AssetData[]; var coreFeesData = (list.Length > 1) ? (list[1] as AssetData[]) : null; var assetObject = (list.Length > 2) ? (list[2] as AssetObject) : null; var dynamicPromise = (!asset.Equals(zeroAsset) && !asset.IsNull()) ? ApiManager.Instance.Database.GetObject <AssetDynamicDataObject>(assetObject.DynamicAssetData) : Promise <AssetDynamicDataObject> .Resolved(null); return dynamicPromise.Then(dynamicObject => { if (!asset.Equals(zeroAsset)) { feePool = !dynamicObject.IsNull() ? dynamicObject.FeePool : 0L; var totalFees = 0L; for (var j = 0; j < coreFeesData.Length; j++) { totalFees += coreFeesData[j].Amount; } if (totalFees > feePool) { feesData = coreFeesData; asset = zeroAsset; } } // Proposed transactions need to be flattened var flatAssets = new List <AssetData>(); Action <object> flatten = null; flatten = obj => { if (obj.IsArray()) { var array = obj as IList; for (var k = 0; k < array.Count; k++) { flatten(array[k]); } } else { flatAssets.Add(( AssetData )obj); } }; flatten(feesData.OrEmpty()); var assetIndex = 0; Action <OperationData> setFee = null; setFee = operation => { if (operation.Fee.IsNull() || operation.Fee.Amount == 0L) { operation.Fee = flatAssets[assetIndex]; } assetIndex++; if (operation.Type.Equals(ChainTypes.Operation.ProposalCreate)) { var proposedOperations = (operation as ProposalCreateOperationData).ProposedOperations; for (var y = 0; y < proposedOperations.Length; y++) { setFee(proposedOperations[y].Operation); } } }; for (var i = 0; i < builder.operations.Count; i++) { setFee(builder.operations[i]); } }); }).Then(results => Promise <TransactionBuilder> .Resolved(builder))); }
public IPromise <GameObject> GetGame(uint id) { return(GetObject <GameObject>(SpaceTypeId.CreateOne(SpaceType.Game, id))); }
public IPromise <MatchObject> GetMatche(uint id) { return(GetObject <MatchObject>(SpaceTypeId.CreateOne(SpaceType.Match, id))); }
public IPromise <TournamentDetailsObject> GetTournamentDetails(uint id) { return(GetObject <TournamentDetailsObject>(SpaceTypeId.CreateOne(SpaceType.TournamentDetails, id))); }