| 290 | } |
| 291 | |
| 292 | func SignTransaction(signer *account.Account, tx *types.MutableTransaction) error { |
| 293 | if tx.Payer == common.ADDRESS_EMPTY { |
| 294 | tx.Payer = signer.Address |
| 295 | } |
| 296 | txHash := tx.Hash() |
| 297 | sigData, err := Sign(txHash.ToArray(), signer) |
| 298 | if err != nil { |
| 299 | return fmt.Errorf("sign error:%s", err) |
| 300 | } |
| 301 | hasSig := false |
| 302 | for i, sig := range tx.Sigs { |
| 303 | if len(sig.PubKeys) == 1 && pubKeysEqual(sig.PubKeys, []keypair.PublicKey{signer.PublicKey}) { |
| 304 | if hasAlreadySig(txHash.ToArray(), signer.PublicKey, sig.SigData) { |
| 305 | //has already signed |
| 306 | return nil |
| 307 | } |
| 308 | hasSig = true |
| 309 | //replace |
| 310 | tx.Sigs[i].SigData = [][]byte{sigData} |
| 311 | } |
| 312 | } |
| 313 | if !hasSig { |
| 314 | tx.Sigs = append(tx.Sigs, types.Sig{ |
| 315 | PubKeys: []keypair.PublicKey{signer.PublicKey}, |
| 316 | M: 1, |
| 317 | SigData: [][]byte{sigData}, |
| 318 | }) |
| 319 | } |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | func MultiSigTransaction(mutTx *types.MutableTransaction, m uint16, pubKeys []keypair.PublicKey, signer *account.Account) error { |
| 324 | pkSize := len(pubKeys) |