コード例 #1
0
        /// <summary>
        /// Returns the Allow Trust XDR Operation Body
        /// </summary>
        /// <returns></returns>
        public override sdkxdr.Operation.OperationBody ToOperationBody()
        {
            var op = new sdkxdr.AllowTrustOp();

            // trustor
            var trustor = new sdkxdr.AccountID();

            trustor.InnerValue = Trustor.XdrPublicKey;
            op.Trustor         = trustor;
            // asset
            var asset = new sdkxdr.AllowTrustOp.AllowTrustOpAsset();

            if (AssetCode.Length <= 4)
            {
                asset.Discriminant = sdkxdr.AssetType.Create(sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM4);
                asset.AssetCode4   = Util.PaddedByteArray(AssetCode, 4);
            }
            else
            {
                asset.Discriminant = sdkxdr.AssetType.Create(sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12);
                asset.AssetCode12  = Util.PaddedByteArray(AssetCode, 12);
            }
            op.Asset = asset;
            // authorize
            op.Authorize = Authorize;

            var body = new sdkxdr.Operation.OperationBody();

            body.Discriminant = sdkxdr.OperationType.Create(sdkxdr.OperationType.OperationTypeEnum.ALLOW_TRUST);
            body.AllowTrustOp = op;
            return(body);
        }
コード例 #2
0
            /// <summary>
            /// Builder to build the AllowTrust Operation given an XDR AllowTrustOp
            /// </summary>
            /// <param name="op"></param>
            /// <exception cref="Exception"></exception>
            public Builder(sdkxdr.AllowTrustOp op)
            {
                _trustor = KeyPair.FromXdrPublicKey(op.Trustor.InnerValue);
                switch (op.Asset.Discriminant.InnerValue)
                {
                case sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM4:
                    _assetCode = Encoding.UTF8.GetString(op.Asset.AssetCode4);
                    break;

                case sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12:
                    _assetCode = Encoding.UTF8.GetString(op.Asset.AssetCode12);
                    break;

                case sdkxdr.AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE:
                    break;

                default:
                    throw new Exception("Unknown asset code");
                }
                _authorize = op.Authorize;
            }