I have a stellar account say "ACCOUNT1" with the following attributes:
- MasterWeight = 2
- Threshold [ 1, 2, 3]
- Signers:
- Masterkey with weight 2
- ed25519_public_key with weight 1 (say ACCOUNT2)
- sha256_hash key with weight 2
Now, I am trying to send a transaction with ACCOUNT2 (weight 1) and sha256 key (weight 2) as signers.
The operation trying to make:
ACCOUNT1's weight to 0
Threshold [1, 1, 1]
Remove sha256_hash key from the signer list
Following are the code snippets of how I am trying to achieve this using go sdk:
1. Create TransactionBuilder
with appropriate operations set
tx, err := build.Transaction(....)
2. Sign the tx with ACCOUNT2's seed and create TransactionEnvelopBuilder
txBEnv, err := tx.Sign("ACCOUNT2's Seed")
3. Create DecoratedSignature
array to populate one more signature
signaturearr := make([]xdr.DecoratedSignature, len(txBEnv.E.Signatures)+1)
4. Populate existing signatures from the txBEnv
for i, element := range txBEnv.E.Signatures{
signaturearr[i] = element
}
5. Create new DecoratedSignature
using Hash(x) key's x
key := getEncodedKey("WORLDISBEAUTIFUL")
key := "WORLDISBEAUTIFUL"
where,
func getEncodedKey(key string ) ([]byte) {
src := []byte(key)
dst := make([]byte, hex.EncodedLen(len(src)))
hex.Encode(dst, src)
return dst
}
ds0 := xdr.DecoratedSignature{
Hint: xdr.SignatureHint(Hint(key)),
Signature: xdr.Signature(key[:]),
Hint: xdr.SignatureHint(Hint([]byte(key))),
Signature: xdr.Signature([]byte(key)),
}
where,
func Hint(publickey []byte) (r [4]byte) {
hasher := sha256.New()
hasher.Write(publickey)
bytekey := hasher.Sum(nil)
copy(r[:], bytekey[len(bytekey) - 4 :])
return
}
6. Finally, insert the DecoratedSignature
of Hash(x) into the array and assign back
signaturearr[len(signaturearr) - 1] = ds0
txBEnv.E.Signatures = signaturearr
txeB64, err := txBEnv.Base64()
I am always receiving Submit transaction error: TransactionResultCodeTxFailed 300 48
as response in my application.
If I use the constructed signed txn and post using Stellar laboratory, I am getting following result.
"result_codes": { "transaction": "tx_failed", "operations": [ "op_bad_auth", "op_success", "op_success" ] },
Well, first operation is failing, where as the next two succeeds!
I am not sure which part I am missing at the moment while creating new DecoratedSignature for sha256 key.
Looking forward to hear from you all on where I am doing wrong.
Update: I am attaching the XDR data as well:
AAAAALrCb69T8V68CmP1PIWYtwGctqvGyy+F418kuSjdJEsgAAABLACdzCoAAAAOAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAALeMMq1cEGEDyDX3wMdlwSy3a/rQI1S8v4Y8Kd671Ed9QAAAAAAAAAAAAAAAkKMrOAAAABAkUzVA5sa7989N9gPfWZgRtI/X56N9wkndB5XZJEARq4KuY/qcbM7j11Zf7dn1WMRCi+/zyQf/Tb6vpjhB8YEA9fYiPIAAAAgNTc0ZjUyNGM0NDQ5NTM0MjQ1NDE1NTU0NDk0NjU1NGM=
Final Update: I have modified the code where I went wrong. Thanks everyone for your time and help. Let this thread help someone in need.