Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.53 KB | None | 0 0
  1. func RandomTransaction() (transaction Transaction) {
  2.  
  3.     rand.Seed(time.Now().UnixNano()) //for have differents numbers at each time
  4.     transaction.TransactionId = Hash(strconv.Itoa(rand.Intn(100)))
  5.     //after it is just random, the id was the one import for my test
  6.     transaction.LastBlockId = randomSha256()
  7.     transaction.Subchain.InitialTransactionId = randomSha256()
  8.     transaction.Subchain.LastStateTransactionId = randomSha256()
  9.     transaction.Timestamp = time.Now()
  10.     transaction.Contract.TransactionType = "opt-in"
  11.     transaction.Contract.Channel = ADDRESS
  12.     transaction.Contract.Features.Start = time.Now()
  13.     transaction.Contract.Features.End = time.Now()
  14.     transaction.Contract.Features.MaxUse = 10
  15.     transaction.Contract.Features.Frequency.FirstPeriod = 1
  16.     transaction.Contract.Features.Frequency.Length = 2
  17.     transaction.Contract.Features.Frequency.UsePerPeriod = 3
  18.     transaction.Contract.Features.Frequency.CurrentPeriod = 4
  19.     transaction.Contract.Features.Destination.Purpose = randomSha256()
  20.     transaction.Contract.Features.Destination.Scope = []string{"0x0af234s3432", "0x4234jl23432afd"}
  21.     transaction.Contract.Signatures.Beneficiary = randomSha256()
  22.     transaction.Contract.Signatures.Emitter = randomSha256()
  23.     transaction.Identification.Random = 5
  24.     transaction.Identification.Beneficiary.Id = randomSha256()
  25.     transaction.Identification.Beneficiary.Checker = randomSha256()
  26.     transaction.Identification.Emitter.Depositary = randomSha256()
  27.     transaction.Identification.Emitter.Id = randomSha256()
  28.     transaction.Identification.Emitter.Checker = randomSha256()
  29.     transaction.Identification.Emitter.Depositary = randomSha256()
  30.     transaction.Script = "1;2;add"
  31.     return
  32. }
  33.  
  34. func randomSha256() Hash {
  35.     sum := sha256.Sum256([]byte(time.Now().String()))
  36.     return Hash(hex.EncodeToString(sum[:]))
  37. }
  38.  
  39. // RandomBlock ...
  40. func RandomBlockWithTranns() (block Block) {
  41.     block.BlockId = randomSha256()
  42.     block.Header.LastMiners.OnPeriod = 23
  43.     block.Header.LastMiners.Valid = []Hash{randomSha256(), randomSha256(), randomSha256()}
  44.     block.Header.LastMiners.Invalid = []Hash{randomSha256(), randomSha256()}
  45.     block.Header.Signature = randomSha256()
  46.     block.Header.PublicKey = randomSha256()
  47.     block.Header.Nonce = randomSha256()
  48.     block.Timestamp = 123432342
  49.     block.Period = 23
  50.     for i := 0; i < 5; i++ { //pour rajouter 5 transactions (comme ca on a une liste)
  51.       block.Transactions = append(block.Transactions, RandomTransaction())
  52.     }
  53.     block.Header.NewTransactions = []Transaction{RandomTransaction(), RandomTransaction()}
  54.     return
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement