Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi-signature #112

Open
codes0003 opened this issue Nov 9, 2023 · 0 comments
Open

multi-signature #112

codes0003 opened this issue Nov 9, 2023 · 0 comments

Comments

@codes0003
Copy link

I need to build a DelegateResource transaction and use multi-signature, please help me correct it

params, err := anypb.New(&core.DelegateResourceContract{
		OwnerAddress:    PublicKeyToAddress(privateKey.PublicKey),
		ReceiverAddress: r,
		Resource:        core.ResourceCode_ENERGY,
		Balance:         3200000000,
		Lock:            false,
		LockPeriod:      50,
	})
	if err != nil {
		return
	}
	multiSigTransaction := &core.Transaction{
		RawData: &core.TransactionRaw{
			Contract: []*core.Transaction_Contract{{
				Type:         core.Transaction_Contract_DelegateResourceContract,
				Parameter:    params,
				PermissionId: 2,
			}},
			
			RefBlockBytes: now.Blockid,
		},
	}
	tx, err := SignTransaction(multiSigTransaction, privateKey)
	if err != nil {
		fmt.Println(err)
	}
	re, err := c.WalletClient.BroadcastTransaction(ctx, multiSigTransaction)
	if err != nil {
		fmt.Println(err)
	}

func SignTransactions(transaction *core.Transaction, privateKey *ecdsa.PrivateKey) (*core.Transaction, error) {
	transaction.GetRawData().Timestamp = time.Now().UnixNano() / 1000000
	rawData, err := proto.Marshal(transaction.GetRawData())
	if err != nil {
		return nil, err
	}
	h256h := sha256.New()
	h256h.Write(rawData)
	hash := h256h.Sum(nil)
	contractList := transaction.GetRawData().GetContract()
	for range contractList {
		signature, err := crypto.Sign(hash, privateKey)
		if err != nil {
			return nil, err
		}
		transaction.Signature = append(transaction.Signature, signature)
	}
	return transaction, nil
}

output

Transaction broadcasted: code:TAPOS_ERROR message:"Tapos check error."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant