// CreateRawTx creates raw transaction func (cn coinEx) CreateRawTx(txIns []coin.TxIn, getKey coin.GetPrivKey, txOuts interface{}) (string, error) { tx := skycoin.Transaction{} for _, in := range txIns { tx.PushInput(cipher.MustSHA256FromHex(in.Txid)) } s := reflect.ValueOf(txOuts) if s.Kind() != reflect.Slice { return "", errors.New("error tx out type") } outs := make([]interface{}, s.Len()) for i := 0; i < s.Len(); i++ { outs[i] = s.Index(i).Interface() } if len(outs) > 2 { return "", errors.New("out address more than 2") } for _, o := range outs { out := o.(skycoin.TxOut) if (out.Coins % 1e6) != 0 { return "", fmt.Errorf("%s coins must be multiple of 1e6", cn.Name) } tx.PushOutput(out.Address, out.Coins, out.Hours) } keys := make([]cipher.SecKey, len(txIns)) for i, in := range txIns { s, err := getKey(in.Address) if err != nil { return "", fmt.Errorf("get private key failed:%v", err) } k, err := cipher.SecKeyFromHex(s) if err != nil { return "", fmt.Errorf("invalid private key:%v", err) } keys[i] = k } tx.SignInputs(keys) tx.UpdateHeader() d, err := tx.Serialize() if err != nil { return "", err } return hex.EncodeToString(d), nil }