Skip to content

Commit

Permalink
Merge pull request #91 from Concordium/contract-update
Browse files Browse the repository at this point in the history
Add ContractUpdate transaction payload
  • Loading branch information
limemloh authored Jan 26, 2024
2 parents 990045f + 49cffff commit d545312
Show file tree
Hide file tree
Showing 37 changed files with 477 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Unreleased changes

- Bugfix
- Switched the GitHub runners from using 'ubuntu-latest' to 'ubuntu-20.04' to ensure compatibility with the default .NET 6 Docker image for the SDK.
- Added
- New GRPC-endpoint: `GetBlockItems`
- New transaction `DeployModule`
- New transactions: `DeployModule` and `UpdateContract`.
- The function `Prepare` has been removed from the `AccountTransactionPayload` class, but is implemented for all subclasses except `RawPayload`.
- Added serialization and deserialization for all instances of `AccountTransactionPayload`
- Breaking
Expand Down
7 changes: 7 additions & 0 deletions ConcordiumNetSdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetBranches", "examples\Get
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetFinalizedBlocks", "examples\GetFinalizedBlocks\GetFinalizedBlocks.csproj", "{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transations.UpdateContract", "examples\UpdateContract\Transations.UpdateContract.csproj", "{DBFBB7D1-E82D-4380-8263-B4B0AC3A6266}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -227,6 +229,10 @@ Global
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Release|Any CPU.Build.0 = Release|Any CPU
{DBFBB7D1-E82D-4380-8263-B4B0AC3A6266}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBFBB7D1-E82D-4380-8263-B4B0AC3A6266}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBFBB7D1-E82D-4380-8263-B4B0AC3A6266}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBFBB7D1-E82D-4380-8263-B4B0AC3A6266}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -269,5 +275,6 @@ Global
{79E97788-D084-487E-8F34-0BA1911C452A} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{26417CD7-2897-47BA-BA9B-C4475187331A} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{DBFBB7D1-E82D-4380-8263-B4B0AC3A6266} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion examples/GetAccountInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetAccountInfo;
internal sealed class GetAccountInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetAccountList/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetAccountList;
internal sealed class GetAccountListOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetAncestors/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetAncestors;
internal sealed class GetAncestorsOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
[Option(
'm',
Expand Down
2 changes: 1 addition & 1 deletion examples/GetBakerList/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBakerList;
internal sealed class GetBakerListOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlockChainParameters/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GetBlockChainParameters;
internal sealed class GetBlockChainParametersOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlockFinalizationSummary/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBlockFinalizationSummary;
internal sealed class GetBlockFinalizationSummaryOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlockInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBlockInfo;
internal sealed class GetBlockInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
4 changes: 2 additions & 2 deletions examples/GetBlockItemStatus/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class GetBlockItemSummaryOptions
[Option(HelpText = "Transaction hash to lookup", Required = true)]
public string TransactionHash { get; set; }

[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.", Default = "http://node.testnet.concordium.com:20000")]
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.", Default = "http://grpc.testnet.concordium.com:20000")]
public string Endpoint { get; set; }
}

Expand All @@ -37,7 +37,7 @@ public static class Program
/// An example showing how one can query transaction status from a node.
/// </summary>
/// <param name="args">GetBlockItemSummaryOptions
/// Example: --endpoint http://node.testnet.concordium.com:20000 --transactionhash 143ca4183d0bb204000ad08e0fd5792985c808861b97f3b81cb9016ad39d09d2
/// Example: --endpoint http://grpc.testnet.concordium.com:20000 --transactionhash 143ca4183d0bb204000ad08e0fd5792985c808861b97f3b81cb9016ad39d09d2
/// </param>
public static async Task Main(string[] args)
{
Expand Down
4 changes: 2 additions & 2 deletions examples/GetBlockItems/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBlockItems;
internal sealed class GetBlocksOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
[Option(
'b',
Expand All @@ -38,7 +38,7 @@ private static async Task Run(GetBlocksOptions o)
IBlockHashInput bi = o.BlockHash != null ? new Given(BlockHash.From(o.BlockHash)) : new LastFinal();

var blockItems = await client.GetBlockItems(bi);

Console.WriteLine($"All block items in block {blockItems.BlockHash}: [");
await foreach (var item in blockItems.Response)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlockPendingUpdates/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBlockPendingUpdates;
internal sealed class GetBlockPendingUpdatesOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
[Option(
'b',
Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlockSpecialEvents/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBlockSpecialEvents;
internal sealed class GetBlockSpecialEventsOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlockTransactionEvents/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace GetBlockTransactionEvents;
internal sealed class GetBlockTransactionEventsOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlocks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GetBlocks;
internal sealed class GetBlocksOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetBlocksAtHeight/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBlocksAtHeight;
internal sealed class GetBlocksAtHeightOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetBranches/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetBranches;
internal sealed class GetBranchesOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetConsensusInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GetConsensusInfo;
internal sealed class GetConsensusInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetFinalizedBlocks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GetFinalizedBlocks;
internal sealed class GetFinalizedBlocksOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetIdentityProviders/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetIdentityProviders;
internal sealed class GetIdentityProvidersOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetInstanceInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GetInstanceInfo;
internal sealed class GetInstanceInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetInstanceList/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetInstanceList;
internal sealed class GetInstanceListOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetModuleList/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetModuleList;
internal sealed class GetModuleListOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetModuleSource/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetModuleSource;
internal sealed class GetModuleSourceOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetNodeInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GetNodeInfo;
internal sealed class GetNodeInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/GetPassiveDelegationInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetPassiveDelegationInfo;
internal sealed class GetPassiveDelegationInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetPoolInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GetPoolInfo;
internal sealed class GetPoolInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion examples/GetTokenomicsInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GetTokenomicsInfo;
internal sealed class GetTokenomicsInfoOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
Default = "http://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }

[Option(
Expand Down
94 changes: 94 additions & 0 deletions examples/UpdateContract/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using CommandLine;
using Concordium.Sdk.Client;
using Concordium.Sdk.Types;
using Concordium.Sdk.Wallets;

namespace Transactions.UpdateContract;

// We disable these warnings since CommandLine needs to set properties in options
// but we don't want to give default values.
#pragma warning disable CS8618

internal sealed class UpdateTransactionExampleOptions
{
[Option(
'k',
"keys",
HelpText = "Path to a file with contents that is in the Concordium browser wallet key export format.",
Required = true
)]
public string WalletKeysFile { get; set; }
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "https://grpc.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
[Option('a', "amount", HelpText = "Amount of CCD to deposit.", Default = 0)]
public ulong Amount { get; set; }

[Option('c', "contract", HelpText = "The index of the smart contract.", Required = true)]
public ulong Contract { get; set; }

[Option('r', "receive-name", HelpText = "The receive_name of the contract to be called.", Required = true)]
public string ReceiveName { get; set; }

[Option('e', "max-energy", HelpText = "The maximum energy to spend on the module.", Required = true)]
public ulong MaxEnergy { get; set; }
}

/// <summary>
/// Example demonstrating how to submit a transaction updating a smart contract.
///
/// The example assumes you have your account key information stored
/// in the Concordium browser wallet key export format, and that a path
/// pointing to it is supplied to it from the command line.
///
/// See <see cref="UpdateTransactionExampleOptions"/> for more info
/// on how to run the program, or refer to the help message.
/// </summary>
internal class Program
{
/// <summary>
/// Example send a contract update transaction.
/// </summary>
public static async Task Main(string[] args) =>
await Parser.Default
.ParseArguments<UpdateTransactionExampleOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(UpdateTransactionExampleOptions options)
{
// Read the account keys from a file.
var walletData = File.ReadAllText(options.WalletKeysFile);
var account = WalletAccount.FromWalletKeyExportFormat(walletData);

// Construct the client.
var clientOptions = new ConcordiumClientOptions
{
Timeout = TimeSpan.FromSeconds(10)
};
using var client = new ConcordiumClient(new Uri(options.Endpoint), clientOptions);

// Create the update transaction.
var amount = CcdAmount.FromCcd(options.Amount);
var contract = ContractAddress.From(options.Contract, 0);
var receiveName = ReceiveName.Parse(options.ReceiveName);
var parameter = Parameter.Empty();
var maxEnergy = new EnergyAmount(options.MaxEnergy);

var updatePayload = new Concordium.Sdk.Transactions.UpdateContract(amount, contract, receiveName, parameter);

// Prepare the transaction for signing.
var sender = account.AccountAddress;
var sequenceNumber = client.GetNextAccountSequenceNumber(sender).Item1;
var expiry = Expiry.AtMinutesFromNow(30);
var preparedPayload = updatePayload.Prepare(sender, sequenceNumber, expiry, maxEnergy);

// Sign the transaction using the account keys.
var signedTransaction = preparedPayload.Sign(account);

// Submit the transaction.
var txHash = await client.SendAccountTransactionAsync(signedTransaction);

// Print the transaction hash.
Console.WriteLine($"Successfully submitted transfer transaction with hash {txHash}");
}
}
Loading

0 comments on commit d545312

Please sign in to comment.