예제 #1
0
func Test_Factoid_Addresses(test *testing.T) {

	addr := NewAddress(primitives.Sha([]byte("A fake address")).Bytes())

	uaddr := primitives.ConvertFctAddressToUserStr(addr)

	if !primitives.ValidateFUserStr(uaddr) {
		test.Fail()
	}

	addrBack := primitives.ConvertUserStrToAddress(uaddr)

	if bytes.Compare(addrBack, addr.Bytes()) != 0 {
		test.Fail()
	}

	buaddr := []byte(uaddr)

	for i, v := range buaddr {
		for j := uint(0); j < 8; j++ {
			if !primitives.ValidateFUserStr(string(buaddr)) {
				test.Fail()
			}
			buaddr[i] = v ^ (01 << j)
			if primitives.ValidateFUserStr(string(buaddr)) {
				test.Fail()
			}
			buaddr[i] = v
		}
	}
}
예제 #2
0
func PublicKeyStringToFactoidAddressString(public string) (string, error) {
	pubHex, err := hex.DecodeString(public)
	if err != nil {
		return "", err
	}
	add, err := PublicKeyToFactoidAddress(pubHex)
	if err != nil {
		return "", err
	}

	return primitives.ConvertFctAddressToUserStr(add), nil
}
예제 #3
0
func HandleV2GetPendingTransactions(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	fmt.Println("HandleV2GetPendingTransactions")
	type PendingTransactions struct {
		TransactionID interfaces.IHash
		Inputs        []interfaces.IInAddress
		Outputs       []interfaces.IOutAddress
		ECOutputs     []interfaces.IOutECAddress
	}
	pending := state.GetPendingTransactions()
	resp := make([]PendingTransactions, len(pending))
	var uAddr string
	var uIAddr interfaces.IAddress
	for i, tran := range pending {
		resp[i].TransactionID = tran.GetSigHash()

		resp[i].Inputs = tran.GetInputs()
		resp[i].Outputs = tran.GetOutputs()
		resp[i].ECOutputs = tran.GetECOutputs()

		for k, _ := range resp[i].Inputs {
			uIAddr = resp[i].Inputs[k].GetAddress()
			uAddr = primitives.ConvertFctAddressToUserStr(uIAddr)
			resp[i].Inputs[k].SetUserAddress(uAddr)
		}
		for k, _ := range resp[i].Outputs {
			uIAddr = resp[i].Outputs[k].GetAddress()
			uAddr = primitives.ConvertFctAddressToUserStr(uIAddr)
			resp[i].Outputs[k].SetUserAddress(uAddr)
		}

		for k, _ := range resp[i].ECOutputs {
			uIAddr = resp[i].ECOutputs[k].GetAddress()
			uAddr = primitives.ConvertECAddressToUserStr(uIAddr)
			resp[i].ECOutputs[k].SetUserAddress(uAddr)

		}

	}
	return resp, nil
}
예제 #4
0
// Make this into somewhat readable text.
func (ta TransAddress) CustomMarshalTextAll(fct bool, label string) ([]byte, error) {
	var out bytes.Buffer
	out.WriteString(fmt.Sprintf("   %8s:", label))
	v := primitives.ConvertDecimalToPaddedString(ta.Amount)
	fill := 8 - len(v) + strings.Index(v, ".") + 1
	fstr := fmt.Sprintf("%%%vs%%%vs ", 18-fill, fill)
	out.WriteString(fmt.Sprintf(fstr, v, ""))
	if fct {
		out.WriteString(primitives.ConvertFctAddressToUserStr(ta.Address))
	} else {
		out.WriteString(primitives.ConvertECAddressToUserStr(ta.Address))
	}
	str := fmt.Sprintf("\n                  %016x %038s\n\n", ta.Amount, string(hex.EncodeToString(ta.GetAddress().Bytes())))
	out.WriteString(str)
	return out.Bytes(), nil
}