// 'Verify the usage of EnumExtension' public void VeryfyCorrectEnumExtension() { //This is the comparison class CompareLogic compareLogic = new CompareLogic(); MembershipType mblack = MembershipType.BLACK; MembershipType mbronze = MembershipType.BRONZE; MembershipType mgold = MembershipType.GOLD; MembershipType msilver = MembershipType.SILVER; String sblack = MyEnumExtensions.ToEnumMemberAttrValue(mblack); String sbronze = MyEnumExtensions.ToEnumMemberAttrValue(mbronze); String sgold = MyEnumExtensions.ToEnumMemberAttrValue(mgold); String ssilver = MyEnumExtensions.ToEnumMemberAttrValue(msilver); Assert.AreEqual(sblack, "black"); Assert.AreEqual(sbronze, "bronze"); Assert.AreEqual(sgold, "gold"); Assert.AreEqual(ssilver, "silver"); BroadcastingMode modeAsync = BroadcastingMode.ASYNC; BroadcastingMode modeBlock = BroadcastingMode.BLOCK; BroadcastingMode modeSync = BroadcastingMode.SYNC; Assert.AreEqual(MyEnumExtensions.ToEnumMemberAttrValue(modeAsync), "async"); Assert.AreEqual(MyEnumExtensions.ToEnumMemberAttrValue(modeBlock), "block"); Assert.AreEqual(MyEnumExtensions.ToEnumMemberAttrValue(modeSync), "sync"); }
/// Creates a new transaction which tells the [recipient] that the document /// having the specified [documentId] and present inside the transaction with /// hash [txHash] has been properly seen. /// [proof] optional proof of reading. public static async Task <TransactionResult> sendDocumentReceipt( String recipient, String txHash, String documentId, Wallet wallet, String proof = "", StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC ) { CommercioDocReceipt commercioDocReceipt = CommercioDocReceiptHelper.fromWallet( wallet: wallet, recipient: recipient, txHash: txHash, documentId: documentId, proof: proof ); MsgSendDocumentReceipt msg = new MsgSendDocumentReceipt(receipt: commercioDocReceipt); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Sends a new transaction from the sender [wallet] /// to request a list of Did PowerUp [requestDidPowerUpsList]. /// Optionally [fee] and broadcasting [mode] parameters can be specified. public static async Task <TransactionResult> requestDidPowerUpList( List <RequestDidPowerUp> requestDidPowerUpsList, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC ) { List <MsgRequestDidPowerUp> msgs = requestDidPowerUpsList .Select(x => new MsgRequestDidPowerUp(x)) .ToList(); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(msgs.ToList <StdMsg>(), wallet, fee : fee, mode : mode)); }
/// Creates a new Did power up request for the given [pairwiseDid] and of the given [amount]. /// Signs everything that needs to be signed (i.e. the signature JSON inside the payload) with the /// private key contained inside the given [senderWallet] and the [privateKey]. public static async Task <TransactionResult> requestDidPowerUp( Wallet senderWallet, String pairwiseDid, List <StdCoin> amount, RSAPrivateKey privateKey, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC ) { RequestDidPowerUp requestDidPowerUp = await RequestDidPowerUpHelper.fromWallet( senderWallet, pairwiseDid, amount, privateKey ); MsgRequestDidPowerUp msg = new MsgRequestDidPowerUp(requestDidPowerUp: requestDidPowerUp); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, senderWallet, fee : fee, mode : mode)); }
// This doesn't seem to be used, although it is there in Dart code... I will keep it as a placeholder // Use static HttpClient to avoid exhausting system resources for network connections. // private static HttpClient client = new HttpClient(); #endregion #region Properties #endregion #region Constructors #endregion #region Public Methods /// Creates a new transaction that allows to share the document associated /// with the given [contentUri] and having the given [metadata] /// and [checksum]. If [encryptedData] is specified, encrypts the proper /// data for the specified [recipients] and then sends the transaction /// to the blockchain. public static async Task <TransactionResult> shareDocument( String id, CommercioDocMetadata metadata, List <String> recipients, Wallet wallet, CommercioDoSign doSign = null, CommercioDocChecksum checksum = null, KeyParameter aesKey = null, List <EncryptedData> encryptedData = null, StdFee fee = null, String contentUri = null, BroadcastingMode mode = BroadcastingMode.SYNC ) { // Build a generic document CommercioDoc commercioDoc = await CommercioDocHelper.fromWallet( wallet : wallet, recipients : recipients, id : id, metadata : metadata, checksum : checksum, contentUri : contentUri, doSign : doSign, encryptedData : encryptedData, aesKey : aesKey ); // Build the tx message MsgShareDocument msg = new MsgShareDocument(document: commercioDoc); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Performs a transaction setting the [didDocuments] list as being /// associated with the address present inside the specified [wallet]. /// Optionally [fee] and broadcasting [mode] parameters can be specified. public static Task <TransactionResult> setDidDocumentsList(List <DidDocument> didDocuments, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { List <MsgSetDidDocument> msgs = didDocuments .Select(x => new MsgSetDidDocument(x)) .ToList(); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg // And I need to declare the thing explicitly in C#! return(TxHelper.createSignAndSendTx(msgs.ToList <StdMsg>(), wallet, fee: fee, mode: mode)); }
/// Performs a transaction setting the specified [didDocument] as being /// associated with the address present inside the specified [wallet]. public static Task <TransactionResult> setDidDocument(DidDocument didDocument, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { MsgSetDidDocument msg = new MsgSetDidDocument(didDocument: didDocument); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee: fee, mode: mode)); }
/// Closes the CDP having the given [timestamp]. /// Optionally [fee] and broadcasting [mode] parameters can be specified. public static async Task <TransactionResult> closeCdp(int timestamp, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { CloseCdp closeCdp = CloseCdpHelper.fromWallet(wallet, timestamp); MsgCloseCdp msg = new MsgCloseCdp(closeCdp: closeCdp); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Performs a transaction opening a new CDP [openCdp] as being /// associated with the address present inside the specified [wallet]. /// Optionally [fee] and broadcasting [mode] parameters can be specified. public static async Task <TransactionResult> openCdpSingle(OpenCdp openCdp, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { MsgOpenCdp msg = new MsgOpenCdp(openCdp: openCdp); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Opens a new CDP depositing the given Commercio Token [amount]. /// Optionally [fee] and broadcasting [mode] parameters can be specified. public static async Task <TransactionResult> openCdp(int amount, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { List <StdCoin> depositAmount = new List <StdCoin> { new StdCoin("ucommercio", amount.ToString()) }; OpenCdp openCdp = OpenCdpHelper.fromWallet(wallet, depositAmount); MsgOpenCdp msg = new MsgOpenCdp(openCdp: openCdp); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Buys the membership with the given [membershipType]. public static async Task <TransactionResult> buyMembership(MembershipType membershipType, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { BuyMembership buyMembership = BuyMembershipHelper.fromWallet(wallet, membershipType); MsgBuyMembership msg = new MsgBuyMembership(buyMembership: buyMembership); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Sends a new transaction in order to invite the given [userDid]. public static async Task <TransactionResult> inviteUser(String userDid, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { InviteUser inviteUser = InviteUserHelper.fromWallet(wallet, userDid); MsgInviteUser msg = new MsgInviteUser(inviteUser: inviteUser); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
/// Creates a transaction having the given [msgs] and [fee] inside, /// signs it with the given [Wallet] and sends it to the blockchain. /// Optional parameters can be [fee] and broadcasting [mode], /// that can be of type "sync", "async" or "block". public static async Task <TransactionResult> createSignAndSendTx(List <StdMsg> msgs, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC) { if (fee == null) { // Set the default value for fee int msgsNumber = msgs.Count > 0 ? msgs.Count : 1; fee = GenericUtils.calculateDefaultFee(msgsNumber: msgsNumber, fee: defaultAmount, denom: defaultDenom, gas: defaultGas); } String modeStr = MyEnumExtensions.ToEnumMemberAttrValue(mode); StdTx stdTx = TxBuilder.buildStdTx(stdMsgs: msgs, fee: fee); StdTx signedTx = await TxSigner.signStdTx(wallet : wallet, stdTx : stdTx); // return await TxSender.broadcastStdTx(wallet: wallet, stdTx: signedTx, mode: modeStr); TransactionResult res = await TxSender.broadcastStdTx(wallet : wallet, stdTx : signedTx, mode : modeStr); return(res); }