4
4
use fil_actors_runtime:: runtime:: builtins:: Type ;
5
5
use fil_actors_runtime:: runtime:: { ActorCode , Runtime } ;
6
6
use fil_actors_runtime:: {
7
- actor_error, cbor, resolve_to_actor_id, restrict_internal_api, ActorDowncast , ActorError , Array ,
7
+ actor_error, cbor, resolve_to_actor_id, restrict_internal_api, ActorDowncast , ActorError ,
8
+ Array , AsActorError ,
8
9
} ;
9
10
use fvm_ipld_blockstore:: Blockstore ;
10
11
use fvm_ipld_encoding:: RawBytes ;
@@ -22,6 +23,7 @@ pub use self::types::*;
22
23
#[ cfg( feature = "fil-actor" ) ]
23
24
fil_actors_runtime:: wasm_trampoline!( Actor ) ;
24
25
26
+ pub mod ext;
25
27
mod state;
26
28
pub mod testing;
27
29
mod types;
@@ -42,17 +44,24 @@ pub const ERR_CHANNEL_STATE_UPDATE_AFTER_SETTLED: ExitCode = ExitCode::new(32);
42
44
43
45
/// Payment Channel actor
44
46
pub struct Actor ;
47
+
45
48
impl Actor {
46
49
/// Constructor for Payment channel actor
47
50
pub fn constructor ( rt : & mut impl Runtime , params : ConstructorParams ) -> Result < ( ) , ActorError > {
48
51
// Only InitActor can create a payment channel actor. It creates the actor on
49
52
// behalf of the payer/payee.
50
53
rt. validate_immediate_caller_type ( std:: iter:: once ( & Type :: Init ) ) ?;
51
54
52
- // Check both parties are capable of signing vouchers
53
- let to = Self :: resolve_account ( rt, & params. to ) ?;
55
+ // Resolve both parties, confirming they exist in the state tree.
56
+ let to = Self :: resolve_address ( rt, & params. to )
57
+ . with_context_code ( ExitCode :: USR_ILLEGAL_ARGUMENT , || {
58
+ format ! ( "to address not found {}" , params. to)
59
+ } ) ?;
54
60
55
- let from = Self :: resolve_account ( rt, & params. from ) ?;
61
+ let from = Self :: resolve_address ( rt, & params. from )
62
+ . with_context_code ( ExitCode :: USR_ILLEGAL_ARGUMENT , || {
63
+ format ! ( "to address not found {}" , params. to)
64
+ } ) ?;
56
65
57
66
let empty_arr_cid =
58
67
Array :: < ( ) , _ > :: new_with_bit_width ( rt. store ( ) , LANE_STATES_AMT_BITWIDTH )
@@ -65,26 +74,14 @@ impl Actor {
65
74
Ok ( ( ) )
66
75
}
67
76
68
- /// Resolves an address to a canonical ID address and requires it to address an account actor .
69
- fn resolve_account ( rt : & mut impl Runtime , raw : & Address ) -> Result < Address , ActorError > {
77
+ /// Resolves an address to a canonical ID address and confirms it exists in the state tree .
78
+ fn resolve_address ( rt : & mut impl Runtime , raw : & Address ) -> Result < Address , ActorError > {
70
79
let resolved = resolve_to_actor_id ( rt, raw) ?;
71
80
72
- let code_cid = rt
73
- . get_actor_code_cid ( & resolved)
74
- . ok_or_else ( || actor_error ! ( illegal_argument, "no code for address {}" , resolved) ) ?;
75
-
76
- let typ = rt. resolve_builtin_actor_type ( & code_cid) ;
77
- if typ != Some ( Type :: Account ) {
78
- Err ( actor_error ! (
79
- forbidden,
80
- "actor {} must be an account, was {} ({:?})" ,
81
- raw,
82
- code_cid,
83
- typ
84
- ) )
85
- } else {
86
- Ok ( Address :: new_id ( resolved) )
87
- }
81
+ // so long as we can find code for this, return `resolved`
82
+ rt. get_actor_code_cid ( & resolved)
83
+ . map ( |_| Address :: new_id ( resolved) )
84
+ . ok_or_else ( || actor_error ! ( illegal_argument, "no code for address {}" , resolved) )
88
85
}
89
86
90
87
pub fn update_channel_state (
@@ -98,10 +95,11 @@ impl Actor {
98
95
let sv = params. sv ;
99
96
100
97
// Pull signature from signed voucher
101
- let sig = sv
98
+ let sig = & sv
102
99
. signature
103
100
. as_ref ( )
104
- . ok_or_else ( || actor_error ! ( illegal_argument, "voucher has no signature" ) ) ?;
101
+ . ok_or_else ( || actor_error ! ( illegal_argument, "voucher has no signature" ) ) ?
102
+ . bytes ;
105
103
106
104
if st. settling_at != 0 && rt. curr_epoch ( ) >= st. settling_at {
107
105
return Err ( ActorError :: unchecked (
@@ -120,9 +118,17 @@ impl Actor {
120
118
} ) ?;
121
119
122
120
// Validate signature
123
- rt. verify_signature ( sig, & signer, & sv_bz) . map_err ( |e| {
124
- e. downcast_default ( ExitCode :: USR_ILLEGAL_ARGUMENT , "voucher signature invalid" )
125
- } ) ?;
121
+
122
+ rt. send (
123
+ & signer,
124
+ ext:: account:: AUTHENTICATE_MESSAGE_METHOD ,
125
+ RawBytes :: serialize ( ext:: account:: AuthenticateMessageParams {
126
+ signature : sig. to_vec ( ) ,
127
+ message : sv_bz,
128
+ } ) ?,
129
+ TokenAmount :: zero ( ) ,
130
+ )
131
+ . map_err ( |e| e. wrap ( "voucher sig authentication failed" ) ) ?;
126
132
127
133
let pch_addr = rt. message ( ) . receiver ( ) ;
128
134
let svpch_id = rt. resolve_address ( & sv. channel_addr ) . ok_or_else ( || {
0 commit comments