Skip to content

Commit

Permalink
bulk upload SC
Browse files Browse the repository at this point in the history
  • Loading branch information
noescape00 committed Jul 21, 2021
1 parent 95e5c34 commit d5d34c2
Show file tree
Hide file tree
Showing 60 changed files with 5,808 additions and 136 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@


Unity3d client for Stratis.



Video manual on how to setup and use basic light wallet functionality: https://youtu.be/hNpdUokMQlE



Smart contract usage example can be found in TestSmartContracts.cs file.

More in depth information on how to create and interact with smart contracts can be found here: https://academy.stratisplatform.com/Operation%20Guides/SmartContracts/smartcontracts-introduction.html

95 changes: 54 additions & 41 deletions Src/StratisUnity3d/Assets/Code/Dependencies/Networks/CirrusMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Stratis.Sidechains.Networks
{
public class CirrusMain : Network
public class CirrusMain : PoANetwork
{
public CirrusMain()
{
Expand Down Expand Up @@ -44,6 +44,7 @@ public CirrusMain()

this.Genesis = genesisBlock;


this.Federations = new Federations();
var straxFederationTransactionSigningKeys = new List<PubKey>()
{
Expand All @@ -66,6 +67,29 @@ public CirrusMain()

// Register the new set of federation members.
this.Federations.RegisterFederation(new Federation(straxFederationTransactionSigningKeys));

// The height at which the following list of members apply.
this.MultisigMinersApplicabilityHeight = 1413998;

// Set the list of Strax Era mining keys.
this.StraxMiningMultisigMembers = new List<PubKey>()
{
new PubKey("02ace4fbe6a622cdfc922a447c3253e8635f3fecb69241f73629e6f0596a567907"),
new PubKey("028e1d9fd64b84a2ec85fac7185deb2c87cc0dd97270cf2d8adc3aa766dde975a7"),
new PubKey("025cb67811d0922ca77fa33f19c3e5c37961f9639a1f0a116011b9075f6796abcb"),
new PubKey("027e793fbf4f6d07de15b0aa8355f88759b8bdf92a9ffb8a65a87fa8ee03baeccd"),
new PubKey("03eb5db0b1703ea7418f0ad20582bf8de0b4105887d232c7724f43f19f14862488"),
new PubKey("03e8809be396745434ee8c875089e518a3eef40e31ade81869ce9cbef63484996d"),
new PubKey("0317abe6a28cc7af44a46de97e7c6120c1ccec78afb83efe18030f5c36e3016b32"),
new PubKey("038e1a76f0e33474144b61e0796404821a5150c00b05aad8a1cd502c865d8b5b92"),
new PubKey("036437789fac0ab74cda93d98b519c28608a48ef86c3bd5e8227af606c1e025f61"),
new PubKey("03d8b5580b7ec709c006ef497327db27ea323bd358ca45412171c644214483b74f"),
new PubKey("02f40bd4f662ba20629a104115f0ac9ee5eab695716edfe01b240abf56e05797e2"),
new PubKey("0323033679aa439a0388f09f2883bf1ca6f50283b41bfeb6be6ddcc4e420144c16"),
new PubKey("03535a285d0919a9bd71df3b274cecb46e16b78bf50d3bf8b0a3b41028cf8a842d"),
new PubKey("03a37019d2e010b046ef9d0459e4844a015758007602ddfbdc9702534924a23695"),
new PubKey("03f5de5176e29e1e7d518ae76c1e020b1da18b57a3713ac81b16015026e232748e"),
};

var buriedDeployments = new BuriedDeploymentsArray
{
Expand All @@ -75,41 +99,7 @@ public CirrusMain()
};

var bip9Deployments = new NoBIP9Deployments();

this.Consensus = new Consensus(
consensusFactory: consensusFactory,
consensusOptions: null,
coinType: 401,
hashGenesisBlock: genesisBlock.GetHash(),
subsidyHalvingInterval: 210000,
majorityEnforceBlockUpgrade: 750,
majorityRejectBlockOutdated: 950,
majorityWindow: 1000,
buriedDeployments: buriedDeployments,
bip9Deployments: bip9Deployments,
bip34Hash: new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"),
minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
maxReorgLength: 240, // Heuristic. Roughly 2 * mining members
defaultAssumeValid: new uint256("0xbfd4a96a6c5250f18bf7c586761256fa5f8753ffa10b24160f0648a452823a95"), // 1400000
maxMoney: Money.Coins(100_000_000),
coinbaseMaturity: 1,
premineHeight: 2,
premineReward: Money.Coins(100_000_000),
proofOfWorkReward: Money.Coins(0),
powTargetTimespan: TimeSpan.FromDays(14), // two weeks
targetSpacing: TimeSpan.FromSeconds(16),
powAllowMinDifficultyBlocks: false,
posNoRetargeting: false,
powNoRetargeting: true,
powLimit: null,
minimumChainWork: null,
isProofOfStake: false,
lastPowBlock: 0,
proofOfStakeLimit: null,
proofOfStakeLimitV2: null,
proofOfStakeReward: Money.Zero
);


// Same as current smart contracts test networks to keep tests working
this.Base58Prefixes = new byte[12][];
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { 28 }; // C
Expand All @@ -130,11 +120,34 @@ public CirrusMain()
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;

this.StandardScriptsRegistry = new PoAStandardScriptsRegistry();

Assert(this.DefaultBanTimeSeconds <= this.Consensus.MaxReorgLength * this.Consensus.TargetSpacing.TotalSeconds / 2);
Assert(this.Consensus.HashGenesisBlock == uint256.Parse("000005769503496300ec879afd7543dc9f86d3b3d679950b2b83e2f49f525856"));
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse("1669a55d45b642af0ce82c5884cf5b8d8efd5bdcb9a450c95f442b9bd1ff65ea"));
this.Checkpoints = new Dictionary<int, CheckpointInfo>()
{
{ 50000, new CheckpointInfo(new uint256("0xf3ed37db1c56751fdf9f45902696dd034444a697cd8c106a08f4c60cd2de9d77")) },
{ 100000, new CheckpointInfo(new uint256("0x1400cb20800d54cd7fff5fea90133a1a8ca44e7043268cd0c7efdd7f8186b2d0")) },
{ 150000, new CheckpointInfo(new uint256("0x505d22805f0fc4ea057edad778e7334412526a7c1b017b179be5d274c8d42914")) },
{ 200000, new CheckpointInfo(new uint256("0x5569221c600e42b0467c92bd932046c12198eee5c50ac98eadff7d3159f55b75")) },
{ 250000, new CheckpointInfo(new uint256("0x1a0d5f43335eff00e8a3b5dc09e4f6849b571b6870eb58364cf86623222922d7")) },
{ 300000, new CheckpointInfo(new uint256("0x3b1c3704e0cb79e7fff46ab7e9feacbfa9e2e95ab90b273d99520dbd42cc34b6")) },
{ 350000, new CheckpointInfo(new uint256("0xcb420b8ef20e1da9eb63b6847005b17928b4bad6c2920eebc964ecf21c50ce5a")) },
{ 400000, new CheckpointInfo(new uint256("0xa501a5c69dfce78e39bf0c25d2c1eafa9fd7a9f32ee06b419d3a3c0a6ac29d8b")) },
{ 450000, new CheckpointInfo(new uint256("0xc3ae6119d23294ac51c05f9c761da5271711b1945592cb83cc1bcc1b908780c7")) },
{ 500000, new CheckpointInfo(new uint256("0x810cc011d6d5158aaefcc38550a31b4118fae1bb18ea7894f81a2edc81126d5f")) },
{ 550000, new CheckpointInfo(new uint256("0x3a6b0a58deb1997879d35fc6e017123594c00eafb3ac45d8c31a5dbf68c2bccc")) },
{ 600000, new CheckpointInfo(new uint256("0xc79bf7066ec9243a335fcd2a43380a47a5b9dccdeaee3f67ab5503cef0cd1626")) },
{ 700000, new CheckpointInfo(new uint256("0xe777ae5e283564a994cbcf88315a594854c12d626e6908fb27e3d0cd7d04fcc7")) },
{ 800000, new CheckpointInfo(new uint256("0xe8b2b9b4e342b0ff9a0b1b967b0f2b7481fe420c5922322d1b77cfae66471fa1")) },
{ 900000, new CheckpointInfo(new uint256("0x30599fbbce4404ebaff9f8d0ea7071c684f124439f1f4e9fabec0debad6c7a06")) },
{ 1_000_000, new CheckpointInfo(new uint256("0x547faf99acb45e2195ea5fbb6873562c44a7696f6571e8a309d6c9f509be064a")) },
{ 1_100_000, new CheckpointInfo(new uint256("0x7abc2882bcb5e9723ba71ff4155ed3c4006ee655e9f52f8787bcae31b4c796a8")) },
{ 1_200_000, new CheckpointInfo(new uint256("0x8411b830270cc9d6c2e28de1c2e8025c57a5673835f63e30708967adfee5a92c")) },
{ 1_300_000, new CheckpointInfo(new uint256("0x512c19a8245316b4d3b13513c7901f41842846f539f668ca4ac349daaab6dc20")) },
{ 1_400_000, new CheckpointInfo(new uint256("0xbfd4a96a6c5250f18bf7c586761256fa5f8753ffa10b24160f0648a452823a95")) },
{ 1_500_000, new CheckpointInfo(new uint256("0x2a1602877a5231997654bae975223762ee636be2f371cb444b2d3fb564e6989e")) },
{ 1_750_000, new CheckpointInfo(new uint256("0x58c96a878efeeffea1b1924b61eed627687900e01588ffaa2f4a161973f01abf")) },
{ 1_850_000, new CheckpointInfo(new uint256("0x6e2590bd9a8eaab25b236c0c9ac314abec70b18aa053b96c9257f2356dec8314")) },
{ 2_150_000, new CheckpointInfo(new uint256("0x4c65f29b5098479cab275afd77d302ebe5ed8d8ef33e02ae54bf185865763f18")) },
{ 2_500_000, new CheckpointInfo(new uint256("0x2853be7b7224840d3d4b60427ea832e9bd67d8fc6bfcd4956b8c6b2414cf8fc2")) },
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ public CirrusTest()

this.SeedNodes = new List<NetworkAddress>();
this.StandardScriptsRegistry = new PoAStandardScriptsRegistry();


Assert(this.DefaultBanTimeSeconds <= this.Consensus.MaxReorgLength * this.Consensus.TargetSpacing.TotalSeconds / 2);
Assert(this.Consensus.HashGenesisBlock == uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"));
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse("cf8ce1419bbc4870b7d4f1c084534d91126dd3283b51ec379e0a20e27bd23633"));
}
}
}
187 changes: 187 additions & 0 deletions Src/StratisUnity3d/Assets/Code/Dependencies/Networks/PoANetwork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using NBitcoin;
using NBitcoin.DataEncoders;
using NBitcoin.Protocol;
using Stratis.Sidechains.Networks;

public class PoANetwork : Network
{
/// <summary> The name of the root folder containing the different PoA blockchains.</summary>
private const string NetworkRootFolderName = "poa";

/// <summary> The default name used for the Stratis configuration file. </summary>
private const string NetworkDefaultConfigFilename = "poa.conf";

/// <summary>
/// This is the height at which collateral commitment height data was committed to blocks.
/// </summary>
public int CollateralCommitmentActivationHeight { get; set; }

/// <summary>
/// The height at which the StraxMiningMultisigMembers become applicable.
/// </summary>
public int? MultisigMinersApplicabilityHeight { get; set; }

/// <summary> The mining keys of the new multisig members to become active with the first Strax-era Cirrus collateral block mined.</summary>
public IList<PubKey> StraxMiningMultisigMembers { get; protected set; }

public IList<Key> FederationKeys { get; set; }

public PoANetwork()
{
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
var messageStart = new byte[4];
messageStart[0] = 0x76;
messageStart[1] = 0x36;
messageStart[2] = 0x23;
messageStart[3] = 0x06;
uint magic = BitConverter.ToUInt32(messageStart, 0);

this.Name = "PoAMain";
this.NetworkType = NetworkType.Mainnet;
this.Magic = magic;
this.DefaultPort = 16438;
this.DefaultMaxOutboundConnections = 16;
this.DefaultMaxInboundConnections = 109;
this.DefaultRPCPort = 16474;
this.DefaultAPIPort = 37221; // TODO: Confirm
this.MaxTipAge = 2 * 60 * 60;
this.MinTxFee = 10000;
this.FallbackFee = 10000;
this.MinRelayTxFee = 10000;
this.RootFolderName = NetworkRootFolderName;
this.DefaultConfigFilename = NetworkDefaultConfigFilename;
this.MaxTimeOffsetSeconds = 25 * 60;
this.CoinTicker = "POA";

// Create the genesis block.
this.GenesisTime = 1513622125;
this.GenesisNonce = 1560058197;
this.GenesisBits = 402691653;
this.GenesisVersion = 1;
this.GenesisReward = Money.Zero;

Block genesisBlock = CreatePoAGenesisBlock(new ConsensusFactory(), this.GenesisTime, this.GenesisNonce, this.GenesisBits, this.GenesisVersion, this.GenesisReward);

this.Genesis = genesisBlock;

var buriedDeployments = new BuriedDeploymentsArray
{
[BuriedDeployments.BIP34] = 0,
[BuriedDeployments.BIP65] = 0,
[BuriedDeployments.BIP66] = 0
};

var bip9Deployments = new NoBIP9Deployments();

var consensusOptions = new ConsensusOptions(
maxBlockBaseSize: 1_000_000,
maxStandardVersion: 2,
maxStandardTxWeight: 150_000,
maxBlockSigopsCost: 20_000,
maxStandardTxSigopsCost: 20_000 / 5, 1
)
{
EnforceMinProtocolVersionAtBlockHeight = 384675, // setting the value to zero makes the functionality inactive
EnforcedMinProtocolVersion = ProtocolVersion.CIRRUS_VERSION, // minimum protocol version which will be enforced at block height defined in EnforceMinProtocolVersionAtBlockHeight
};

this.Consensus = new Consensus(
consensusFactory: new ConsensusFactory(),
consensusOptions: consensusOptions,
coinType: 401,
hashGenesisBlock: genesisBlock.GetHash(),
subsidyHalvingInterval: 210000,
majorityEnforceBlockUpgrade: 750,
majorityRejectBlockOutdated: 950,
majorityWindow: 1000,
buriedDeployments: buriedDeployments,
bip9Deployments: bip9Deployments,
bip34Hash: new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"),
minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
maxReorgLength: 240, // Heuristic. Roughly 2 * mining members
defaultAssumeValid: new uint256("0xbfd4a96a6c5250f18bf7c586761256fa5f8753ffa10b24160f0648a452823a95"), // 1400000
maxMoney: Money.Coins(100_000_000),
coinbaseMaturity: 1,
premineHeight: 2,
premineReward: Money.Coins(100_000_000),
proofOfWorkReward: Money.Coins(0),
powTargetTimespan: TimeSpan.FromDays(14), // two weeks
targetSpacing: TimeSpan.FromSeconds(16),
powAllowMinDifficultyBlocks: false,
posNoRetargeting: false,
powNoRetargeting: true,
powLimit: null,
minimumChainWork: null,
isProofOfStake: false,
lastPowBlock: 0,
proofOfStakeLimit: null,
proofOfStakeLimitV2: null,
proofOfStakeReward: Money.Zero
);

// https://en.bitcoin.it/wiki/List_of_address_prefixes
this.Base58Prefixes = new byte[12][];
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (55) }; // 'P' prefix
this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (117) }; // 'p' prefix
this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (63 + 128) };
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
this.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
this.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
this.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
this.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
this.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
this.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
this.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };

this.Checkpoints = new Dictionary<int, CheckpointInfo>
{
{ 0, new CheckpointInfo(new uint256("0x0621b88fb7a99c985d695be42e606cb913259bace2babe92970547fa033e4076")) },
};

var encoder = new Bech32Encoder("bc");
this.Bech32Encoders = new Bech32Encoder[2];
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;

this.StandardScriptsRegistry = new PoAStandardScriptsRegistry();

Assert(this.Consensus.HashGenesisBlock == uint256.Parse("0x0621b88fb7a99c985d695be42e606cb913259bace2babe92970547fa033e4076"));
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse("0x9928b372fd9e4cf62a31638607344c03c48731ba06d24576342db9c8591e1432"));
}

protected static Block CreatePoAGenesisBlock(ConsensusFactory consensusFactory, uint nTime, uint nNonce, uint nBits, int nVersion, Money genesisReward)
{
string data = "506f41202d204345485450414a6c75334f424148484139205845504839";

Transaction txNew = consensusFactory.CreateTransaction();
txNew.Version = 1;
// TODO: Removing the time field will affect the genesis block hash of the Cirrus networks. Need to make a call about only developing Cirrus via the SBFN project that still has nTime
txNew.AddInput(new TxIn()
{
ScriptSig = new Script(Op.GetPushOp(0), new Op()
{
Code = (OpcodeType)0x1,
PushData = new[] { (byte)42 }
}, Op.GetPushOp(Encoders.ASCII.DecodeData(data)))
});
txNew.AddOutput(new TxOut()
{
Value = genesisReward,
});

Block genesis = consensusFactory.CreateBlock();
genesis.Header.BlockTime = Utils.UnixTimeToDateTime(nTime);
genesis.Header.Bits = nBits;
genesis.Header.Nonce = nNonce;
genesis.Header.Version = nVersion;
genesis.Transactions.Add(txNew);
genesis.Header.HashPrevBlock = uint256.Zero;
genesis.UpdateMerkleRoot();
return genesis;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5d34c2

Please sign in to comment.