public async Task <bool> Add(Promise promise, ApplicationUser user)
        {
            //it's guaranteed it's unique by contract code
            var counter = await GetPromiseCount(user);

            promise.Id = (counter == 0) ? 1 : counter + 1;

            var json    = JsonConvert.SerializeObject(promise);
            var jsonHex = SmartPromiseConverter.Str2Hex(json);
            var revSh   = await SmartPromiseConverter.GetScriptHashReversed(user.Address, _blockchain);

            var res = await _blockchain.InvokeContractAdd(NETWORK_TYPE.TESTNET, user.Wif, revSh, jsonHex, GAS_COST);

            return(res);
        }
Ejemplo n.º 2
0
        public async Task <bool> SendAsset(NETWORK_TYPE type, ASSET_NAME assetName, string addr, int amount)
        {
            var user = await _userManager.GetUserAsync(User);

            if (assetName == ASSET_NAME.SC)
            {
                var toSh = await SmartPromiseConverter.GetScriptHashReversed(addr, _blockchain);

                var fromSh = await SmartPromiseConverter.GetScriptHashReversed(user.Address, _blockchain);

                var res = await _blockchain.InvokeContractTransfer(type, user.Wif, fromSh, toSh, amount, 1);

                return(res);
            }
            else
            {
                return(await _blockchain.SendAsset(type, user.Wif, assetName, addr, amount));
            }
        }
        public async Task <bool> Complete(int id, string proof, ApplicationUser user)
        {
            var promise = await Get(id, user);

            if (promise == null)
            {
                return(false);
            }

            promise.Status = PROMISE_STATUS.COMPLETED;
            promise.Proof  = proof;
            var json    = JsonConvert.SerializeObject(promise);
            var jsonHex = SmartPromiseConverter.Str2Hex(json);
            var revSh   = await SmartPromiseConverter.GetScriptHashReversed(user.Address, _blockchain);

            var res = await _blockchain.InvokeContractReplace(NETWORK_TYPE.TESTNET, user.Wif, revSh, jsonHex, id, GAS_COST);

            return(res);
        }