1
- import { TransactionInput , InvokeCodeParams , ExtraGeneratParams } from "../types"
1
+ import { TransactionInput , InvokeCodeParams , ExtraGeneratParams , Payment , PaymentGeneratParams } from "../types"
2
2
import { v4 as newUUID , parse , stringify } from 'uuid'
3
3
import { Encoder } from "../mixin/encoder"
4
4
import { base64url } from "../mixin/sign"
@@ -12,6 +12,10 @@ const OperationPurposeGroupEvent = 1
12
12
// const OperationPurposeAddProcess = 11
13
13
// const OperationPurposeCreditProcess = 12
14
14
15
+ const mvmClient = axios . create ( {
16
+ baseURL : 'https://mvm-api.test.mixinbots.com' ,
17
+ } )
18
+
15
19
const receivers = [
16
20
"a15e0b6d-76ed-4443-b83f-ade9eca2681a" ,
17
21
"b9126674-b07d-49b6-bf4f-48d965b2242b" ,
@@ -60,18 +64,18 @@ export const extraGeneratByInfo = async (params: ExtraGeneratParams): Promise<st
60
64
if ( ! methodID ) methodID = getMethodIdByAbi ( methodName ! , types )
61
65
if ( types . length != values . length ) return Promise . reject ( 'error: types.length!=values.length' )
62
66
let extra = contractAddress + methodID
63
- let opcode : number = 0
64
- const { uploadkey, delegatecall, process = registryProcess , address = registryAddress } = options
67
+ const { uploadkey, delegatecall, ignoreUpload, process = registryProcess , address = registryAddress } = options
65
68
if ( types . length !== 0 ) {
66
69
const abiCoder = new utils . AbiCoder ( )
67
70
extra += abiCoder . encode ( types , values ) . slice ( 2 )
68
71
}
69
- const memo = encodeMemo ( extra , process )
70
- if ( memo . length > 200 ) {
72
+ if ( ignoreUpload ) return extra
73
+ let opcode : number = 0
74
+ if ( encodeMemo ( extra , process ) . length > 200 ) {
71
75
if ( ! uploadkey ) return Promise . reject ( 'please provide key to generate extra(length > 200)' )
72
76
const raw = '0x' + extra
73
77
const key = utils . keccak256 ( raw )
74
- const res = await axios . post ( `https://mvm-api.test.mixinbots.com /` , { uploadkey, key, raw, address } )
78
+ const res = await mvmClient . post ( `/` , { uploadkey, key, raw, address } )
75
79
if ( ! res . data . hash ) return Promise . reject ( res )
76
80
opcode += 1
77
81
extra = key . slice ( 2 )
@@ -80,11 +84,23 @@ export const extraGeneratByInfo = async (params: ExtraGeneratParams): Promise<st
80
84
return ( '0' + opcode + extra ) . toLowerCase ( )
81
85
}
82
86
87
+ export const paymentGeneratByInfo = async ( params : PaymentGeneratParams ) : Promise < Payment > => {
88
+ if ( ! params . options ) params . options = { }
89
+ params . options . ignoreUpload = true
90
+ const extra = await extraGeneratByInfo ( params )
91
+ const { type, trace, asset, amount } = params . payment || { }
92
+ const { process, delegatecall, uploadkey, address } = params . options
93
+ const res = await mvmClient . post ( '/payment' , {
94
+ extra,
95
+ process, delegatecall, uploadkey, address,
96
+ type, trace, asset, amount
97
+ } )
98
+ return res . data
99
+ }
83
100
84
101
export const getContractByAssetID = ( id : string , processAddress = registryAddress ) : Promise < string > =>
85
102
getRegistryContract ( processAddress ) . contracts ( '0x' + Buffer . from ( parse ( id ) as Buffer ) . toString ( 'hex' ) )
86
103
87
-
88
104
export const getContractByUserIDs = ( ids : string | string [ ] , threshold ?: number , processAddress = registryAddress ) : Promise < string > => {
89
105
if ( typeof ids === 'string' ) ids = [ ids ]
90
106
if ( ! threshold ) threshold = ids . length
0 commit comments